Skip to content

Instantly share code, notes, and snippets.

@23jodys
Created October 5, 2017 02:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 23jodys/622c13bcf0fc3d299761f84cf7b37364 to your computer and use it in GitHub Desktop.
Save 23jodys/622c13bcf0fc3d299761f84cf7b37364 to your computer and use it in GitHub Desktop.
Declarative Jenkinsfile Environment Variables
pipeline {
agent any
stages {
stage('Example') {
environment {
// 'This value is exported to all commands in this stage'
AWESOME_BUILD = "${env.BUILD_ID + '/working'}"
}
steps {
sh 'mkdir -p $AWESOME_BUILD'
sh 'touch $AWESOME_BUILD/the_file'
// Try to export the variable
sh 'export AWESOME_FILE=$AWESOME_BUILD/the_file'
// But it won't show up here!
sh 'echo $AWESOME_FILE'
// However, if we bundle it in a single sh command
// it will work.
sh '''
export AWESOME_FILE=$AWESOME_BUILD/the_file
echo $AWESOME_FILE
'''
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment