Sathyakumar Seshachalam
Sathyakumar Seshachalam

Reputation: 2053

Token replacement in a Jenkins Config file

I have a deployment pipeline job thats in need of a deployment template file. There are some secure passwords in that file that I want to keep secure.

So I added a Config file provider plugin (v 2.13) and had placeholders in it that corresponded to global passwords. This unfortunately is not working. Just to test I had a Jenkinsfile like below

node {
    checkout scm
    withEnv(['INSTANCE=Something']) {
        configFileProvider(
            [configFile(fileId: 'prescribe', variable: 'DEPLOY_FILE')]) {
            sh "echo $env.INSTANCE" 
            sh "cat ${env.DEPLOY_FILE}"
        }
    }
}

And the file with id 'prescribe' as

${branch}

${ENV, var=INSTANCE}

${ENV.INSTANCE}
${ENV,INSTANCE}

${env, var=INSTANCE}

And I tried keeping INSTANCE as also a global password, global variable. However none of the tokens are replaced.

Any ideas what I'm doing wrong.

Upvotes: 1

Views: 4007

Answers (2)

jonhattan
jonhattan

Reputation: 490

Problem here is that Token Macro only accepts predefined env vars.

Options:

  • Job parameters, as stated by @Taringalio in another answer
  • Try and provide env vars via EnvInject plugin

Please see the related issue in the jenkins tracker https://issues.jenkins-ci.org/browse/JENKINS-39998

Upvotes: 0

Taringalio
Taringalio

Reputation: 41

The only way that i get it working, was using the parameters of the job configuration. And in the file i use this interpolation

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings>
    <add key="overrideDefaultEndpoint" value="true" />
    <add key="endpoint" value="${ENDPOINT}"/>

where ENDPOINT is the name of the job parameter.

Upvotes: 2

Related Questions