I’m trying to write a pipeline that pulls code from a Bitbucket repo, build it, package it into an RPM, and then pushes the RPM to a Nexus repo. It all works if I hardcode the filename into the Nexus step, but when I try to use a variable I keep getting errors. I’ve looked through the docs and found the environmental variables built into Jenkins and also Bitbucket, but when I try to test them with an echo or sh
I run into errors or it tells me there’s no variable with that name. Here’s the beginning of my pipeline up to the test:
pipeline {
agent {
label 'nodejs'
}
parameters {
choice choices: ['dev', 'alpha', 'reseller', 'integrate', 'productioncp', 'productionc1', 'productionc2'], description: 'Describe the environment we want to build for.', name: 'ENVIRONMENT'
booleanParam name: 'RUN_VERACODE', defaultValue: false, description: 'Run Veracode Scan'
}
triggers {
bitbucketPush buildOnCreatedBranch: true, overrideUrl: '<repo URL>'
}
options {
buildDiscarder logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '12', daysToKeepStr: '', numToKeepStr: '12')
}
stages {
stage ('Checking out from BitBucket') {
steps {
bbs_checkout(
branches: [
[name: '*/develop']
],
credentialsId: '<redacted>',
id: '<redacted>',
projectName: '<project>',
repositoryName: '<repo name>',
serverId: '<redacted>',
sshCredentialsId: 'bitbucket-ssh'
)
}
}
stage ('test') {
steps {
script {
echo 'Running tests'
echo ${BRANCH_NAME} ${TAG_NAME} ${JOB_NAME} ${GIT_BRANCH} ${BITBUCKET_REPO_SLUG}
}
}
}
I’ve also tried the following:
echo "${BRANCH_NAME}"
echo ${BRANCH_NAME}
echo BRANCH_NAME
echo env.BRANCH_NAME
sh "echo BRANCH_NAME ${BRANCH_NAME}"
I either get an error along the lines of:
git rev-list --no-walk 7a7a238ce08201d420b1b2511bd5af387a235ad9 # timeout=10
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 50: expecting '}', found 'Running tests' @ line 50, column 26.
- echo 'Running tests'
^
or
> git rev-list --no-walk 61282f8f91c53cc5e759670c6d914d55d62812fd # timeout=10
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 44: Expected a symbol @ line 44, column 17.
echo BRANCH_NAME TAG_NAME JOB_NAME
^
and finally
[Pipeline] End of Pipeline
groovy.lang.MissingPropertyException: No such property: BRANCH_NAME for class: groovy.lang.Binding
at groovy.lang.Binding.getVariable(Binding.java:63)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.java:266)