Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-39998

Token expansion of a config file not happening

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved (View Workflow)
    • Priority: Major
    • Resolution: Fixed
    • Labels:
      None
    • Environment:
      Jenkins version : 2.7.1
      Config file provider plugin : 2.13
    • Similar Issues:

      Description

      I have a config file with some tokens that I expected to be replaced when used with a buildWrapper. But this did not work for me. My pipeline reads like

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

      And my 'prescribe' id'ed file looks like

      ${INSTANCE}
      ${branch}
      
      ${ENV, var=INSTANCE}
      
      ${ENV.INSTANCE}
      ${ENV,INSTANCE}
      
      ${env, var=INSTANCE}
      

      However the file does not come out as token replaced. I have also tried providing INSTANCE as a global password and global variable with the same result

        Attachments

          Activity

          sathyakumars Sathyakumar Seshachalam created issue -
          sathyakumars Sathyakumar Seshachalam made changes -
          Field Original Value New Value
          Description I have a config file with some tokens that I expected to be replaced when used with a buildWrapper. But this did not work for me. My pipeline reads like
          {noformat}
          node {
              checkout scm
              withEnv(['INSTANCE=Something']) {
                  configFileProvider(
                      [configFile(fileId: 'prescribe', variable: 'DEPLOY_FILE')]) {
                      sh "echo $env.INSTANCE"
                      sh "cat ${env.DEPLOY_FILE}"
                  }
              }
          }
          {noformat}

          And my 'prescribe' id'ed file looks like

          {noformat}
          ${branch}

          ${ENV, var=INSTANCE}

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

          ${env, var=INSTANCE}
          {noformat}

          However the file does not come out as token replaced. I have also tried providing INSTANCE as a global password and global variable with the same result
          I have a config file with some tokens that I expected to be replaced when used with a buildWrapper. But this did not work for me. My pipeline reads like
          {noformat}
          node {
              checkout scm
              withEnv(['INSTANCE=Something']) {
                  configFileProvider(
                      [configFile(fileId: 'prescribe', variable: 'DEPLOY_FILE')]) {
                      sh "echo $env.INSTANCE"
                      sh "cat ${env.DEPLOY_FILE}"
                  }
              }
          }
          {noformat}

          And my 'prescribe' id'ed file looks like

          {noformat}
          ${INSTANCE}
          ${branch}

          ${ENV, var=INSTANCE}

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

          ${env, var=INSTANCE}
          {noformat}

          However the file does not come out as token replaced. I have also tried providing INSTANCE as a global password and global variable with the same result
          scm_issue_link SCM/JIRA link daemon made changes -
          Status Open [ 1 ] Resolved [ 5 ]
          Resolution Fixed [ 1 ]
          michaelpporter Michael Porter made changes -
          Comment [ Apologies for posting on a closed ticket. I am having the same issue and could use some help if you are able.

          I am wanting to create a settings.php file for Drupal or Wordpress.

          Test file

           
          {code:java}
          ${ENV, var="X_DB_USER"}
          ${ENV, var="X_SITENAME"}
          ${ENV, var="DOMAIN_NAME"}
          {code}
          Pipeline:

           

           
          {code:java}
          pipeline {
          environment {
          dbName = "test-${env.BUILD_NUMBER}"
          X_SITENAME = "${dbName}"
          X_DB_USER = "mp"
          DOMAIN_NAME = "https://www.example.com"
          }
          agent {
          node {
          label "ww7"
          }
          }
          stages {
          stage("init") {
          steps {
          configFileProvider(
          [
          configFile(
          fileId: 'drupal7-test',
          replaceTokens: true,
          targetLocation: "/var/www/${dbName}/www/local.settings.php")
          ]) {
          // some block
          }
          }
          }
          }
          }


          {code}
          File output

           

           
          {code:java}
          <empty>{code}
           

          If I add a global environment variable it will write to the file, but I am unable to overwrite the values.

           
          {code:java}
          X_DB_USER global placeholder
          X_SITENAME global placeholder
          DOMAIN_NAME global placeholder
          {code}
           

           

          Using the web interface to add a file using job parameters I am able to use a file like:

           
          {code:java}
          <?php
          $$databases = array (
          'default' =>
          array (
          'default' =>
          array (
          'database' => '${DATABASE_NAME}',
          'username' => '${DATABASE_USER}',
          'password' => '${DATABASE_USER}',
          'host' => 'localhost',
          'port' => '',
          'driver' => 'mysql',
          'prefix' => '',
          // 'pdo' => array(ATTR_TIMEOUT => 2.0, MYSQL_ATTR_COMPRESS => 1, MYSQL_ATTR_USE_BUFFERED_QUERY => 1),
          ),
          ),
          );
          {code}
           

          How can I use dynamic variables pulled from a Jenkinsfile?

            ]

            People

            • Assignee:
              domi Dominik Bartholdi
              Reporter:
              sathyakumars Sathyakumar Seshachalam
            • Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: