How to append a text to a file in jenkinsfile

前端 未结 3 1345
清酒与你
清酒与你 2021-02-19 02:43

How to append a text to a file in Jenkinsfile injecting Jenkins BUILD_ID

I wish to see

version := \"1.0.25\"

3条回答
  •  走了就别回头了
    2021-02-19 03:19

    env.BUILD_ID is a groovy variable, not a shell variable. Since you used single-quotes (') groovy will not substitute the variables in your string and the shell doesn't know about ${env.BUILD_ID}. You need to either use double-quotes " and let groovy do the substitution

    sh "echo version := 1.0.${env.BUILD_ID} >> build.sbt"
    

    or use the variable the shell knows

    sh 'echo version := 1.0.$BUILD_ID >> build.sbt'
    

    and since you need the version surrounded with doublequotes, you'd need something like this:

    sh "echo version := \\\"1.0.${env.BUILD_ID}\\\" >> build.sbt"
    

提交回复
热议问题