Unfortunately not.
[branch_jenkins-dummy_master-ZKZSOZRU2C4BR7MTP6RRGC4D2OPUWJONM6DQP6YFBP3UB5R3DCYQ]
Running shell script
+ env
+ sort
BRANCH_NAME=master
BUILD_DISPLAY_NAME=#13
BUILD_ID=13
BUILD_NUMBER=13
BUILD_REVISION=null
BUILD_TAG=jenkins-testing-multibranch-jenkins-dummy-master-13
...
It's specifically the inclusion of ${currentBuild.*property*} in the
variable declaration within the *environment{}* block that leaves the
variable null.
On Wednesday, May 10, 2017 at 12:07:31 PM UTC-5, Cuong Tran wrote:
>
> Does it work with this?
>
> withEnv(["BUILD_REVISION=${env.BUILD_REVISION}"]) {
> sh "env | sort"
> }
>
> On Wednesday, May 10, 2017 at 8:20:45 AM UTC-7, JG wrote:
>>
>> I'm trying to set an env variable globally in my *pipeline {} *with a
>> concatenation of build details like this
>>
>> #!groovy
>> pipeline {
>> agent {
>> label "linux"
>> }
>> parameters {
>> string(name: "releaseName", defaultValue: "RM_TEST", description:
>> "Ivy release spec")
>> }
>> tools {
>> jdk 'jdk1.8.0_102'
>> maven 'maven-3.2.5'
>> }
>> environment {
>> BUILD_REVISION =
>> "${params.releaseName}.${env.BRANCH_NAME}.${currentBuild.startTimeInMillis}.${env.BUILD_ID}"
>> RELEASE_NAME = "${params.releaseName}"
>> }
>> stages {
>> stage("dummy") {
>> steps {
>> sh "echo
>> \"${params.releaseName}.${env.BRANCH_NAME}.${currentBuild.startTimeInMillis}.${env.BUILD_ID}\""
>> sh "env | sort"
>> }
>> }
>> }
>> }
>>
>> and it seems to be silently failing. The *echo* command prints the value
>> as expected, but the *env *does not include a *BUILD_REVISION* variable
>> (the *RELEASE_NAME* env variable is shown in the output of *env*. I also
>> tried setting the *BUILD_REVISION* in an *environment{}* block within
>> the stage, and also tried using a string property of *currentBuild*.
>> Nothing seems to work.
>>
>> It seems to work using *withEnv*
>>
>> steps {
>> sh "echo
>> \"${params.releaseName}.${env.BRANCH_NAME}.${currentBuild.startTimeInMillis}.${env.BUILD_ID}\""
>>
>> withEnv(["BUILD_REVISION=${params.releaseName}.${env.BRANCH_NAME}.${currentBuild.startTimeInMillis}.${env.BUILD_ID}"])
>>
>> {
>> sh "env | sort"
>> }
>> }
>>
>> But I'll need to use the variable in multiple stages so I'd prefer it to
>> be in a global *environment{}* block.
>>
>
--
You received this message because you are subscribed to the Google Groups
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/jenkinsci-users/7698393c-8c2d-4ea7-905d-a9e12ae601d3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.