Search code examples
jenkinsjenkins-pipelinestring-interpolation

How to avoid interpolation of sensitive variables for a bat command in Jenkins


on Linux you can replace the double quotes by single quotes to avoid interpolation.

// WRONG!
sh("curl -u ${EXAMPLE_CREDS_USR}:${EXAMPLE_CREDS_PSW} https://example.com/")

// CORRECT!
sh('curl -u $EXAMPLE_CREDS_USR:$EXAMPLE_CREDS_PSW https://example.com/')

On Windows however, I'm not getting this to work.

Next command will work:

bat "mvn ${MAVENARGS} package -Ddlc=${DLC}"

But next command doesn't work:

bat 'mvn $MAVENARGS package -Ddlc=$DLC'

So how do you do this for a bat script?


Solution

  • Should be

    bat 'mvn %MAVENARGS% package -Ddlc=%DLC%'
    

    On Windows.