0

I am trying to generate some env. variable in jenkins pipeline project and want to inject them into my build, but so far i am not able to do so, in the below mentioned snippet, i have one env variable already created i.e. build=20160107 random build number, now i execute a batchscript name CalculateTempEnvVariablesForBuild.bat which generate TempEnvVariables.properties file. This properties file contains update value of year,Week_number, week_day and now i need to update my build variable as per ${year}0${Week_number}${week_day}

pipeline {
    agent { label 'Build_Machine_Windows_Server' }
    stages {
       stage('Build') {
          steps {
            dir ('E:\\\\Jenkins'){
                 bat 'call E:\\Jenkins\\CalculateTempEnvVariablesForBuild.bat'   

            }  
             load "E:\\Jenkins\\TempEnvVariables.properties" 

             withEnv(['build=${year}0${Week_number}${week_day}']) {
                      echo "${build}"    
                    }

             echo "${year}"
             echo "${week_day}"
             echo "${Week_number}"
          }
       }
    }
}

when i do echo ${build}, its no giving me update value instead it gives me plain string -> ${year}0${Week_number}${week_day} what i need is 20173203 when i do echo of year, week_day and Week_number individually, i get correct value like 17,32,03

I guess i am not setting/injecting variable correctly (may be syntax error)

1 Answer 1

1

The pipeline code is using single quotes. According to the docs, this means interpolation is NOT done by groovy, but by the underlying shell:

(Note that here we are using single quotes in Groovy, so the variable expansion is being done by the Bourne shell, not Jenkins.)

Try using double quotes:

withEnv(["build=${BUILD_NUMBER}"]) {
    echo env.build
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.