Say I have a JSON as following:
{"id":"1.0.0-6",
"version":"1.0.0",
"build":6,
"tag":"android-v1.0.0-6",
"commitHash":"5a78c4665xxxxxxxxxxe1b62c682f84",
"dateCreated":"2020-03-02T08:11:29.912Z"}
I want to take out the version id from it in Jenkins Groovy file and pass the version id to a JIRA Plugin called XRAY so that it will create a build version as Label in JIRA.
stage('Get App version') {
steps {
container('devicefarm') {
steps {
sh "LATEST_VERSION=$(curl ${APP_ARTIFACTORY_URL}/${XRAY_PLATFORM}/builds/latest.json | sed \"s/.*$VERSION_KEY\":\"\\([^\"]*\\).*/'\\1'/\")"
}
}
}
}
environment {
AWS_DEFAULT_REGION = 'uk-xxx'
XRAY_ENVIRONMENT = 'e2e'
VERSION_KEY = 'id'
XRAY_PLATFORM = 'Android'
APP_ARTIFACTORY_URL = 'https://artifactory.example.com/mobile'
LATEST_VERSION = ''
}
I have two questions, will the result of curl command been assigned to variable defined in the same Jenkins file called 'LATEST_VERSION' as expected?
I probably can test it by running the pipe line on Jenkins but I got another issue that prevent me from doing this, it complains that 'Identifier or code block expected'.
While running same in a sh file, it doesn't have this issue, version id was retrieved from JSON as expected.