Here is the jenkins script I am running (Groovy)
SLACK_CHANNEL = 'monitoring'
node {
properties([
buildDiscarder(logRotator(numToKeepStr: '30')),
pipelineTriggers([
cron('00 08 * * 0-5')
]),
parameters([
choice(
name: 'ENVIRONMENT',
choices: environments(default: 'prd'),
),
string(
name: 'EMAIL_TO',
defaultValue: '[email protected]'
)
])
])
try {
def api = ts.getApi(environmentName: params.ENVIRONMENT)
def content = []
content.add '"FirstName","LastName","EmailAddress","LastLoginDate","DeactivatedDate","CompanyName","SecurityProfiles","UserGroups"'
api.clients.each { client ->
api.getUsers(client).each { user ->
def userGroups = user?.userGroups?.collect { userGroup ->
userGroup.group.shortName
}
content.add sprintf(
'"%s","%s","%s","%s","%s","%s","%s","%s"',
user.firstName ?: '',
user.lastName ?: '',
user.emailAddress ?: '',
user.lastLoginDate ?: '',
user?.expiryDate ?: '',
client.company ?: '',
user.securityProfiles?.sort().join(',') ?: '',
userGroups?.sort().join(',') ?: '',
)
}
}
writeFile file: 'users.csv', text: content.join('\n'), encoding: 'utf-8'
sh 'zip users *.csv && rm users.csv'
archiveArtifacts 'users.*'
emailext(
subject: "Active Users Report",
body: "Report was run against the $params.ENVIRONMENT environment. See the attachment.",
to: params.EMAIL_TO,
replyTo: '[email protected]',
attachmentsPattern: 'users.zip'
)
} catch(Exception e) {
notifySlack(
channel: SLACK_CHANNEL,
title: 'Active Users Report',
text: 'Ran into an error when generating the report.',
status: 'danger',
fields: [[
title: "Exception",
value: "```${e.message}```"
]]
)
throw new Exception('Unable to send report.', e)
}
}
When i run this script it gives me below error :
hudson.remoting.ProxyException: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type `[Lcom.ABC.jenkins.model.User;` from Object value (token `JsonToken.START_OBJECT`)
at [Source: (String)"{"errors":["org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is org.hibernate.HibernateException: Could not alter JDBC connection to specified schema [ms_lucirahealth]","Could not alter JDBC connection to specified schema [ms_lucirahealth]"],"errorMessages":[]}"; line: 1, column: 1]
as per my understanding, This error indicates that the Jackson library, which is used for JSON deserialization in my Jenkins pipeline, is expecting an array of com.ABC.jenkins.model.User objects but instead is receiving a JSON object (JsonToken.START_OBJECT).
Can you please share What could be the possible reason and solution to this ? Thanks in advance !!