[JIRA] (JENKINS-48562) Inline Environment Variables not replaced in config file

1 view
Skip to first unread message

domi@fortysix.ch (JIRA)

unread,
Mar 5, 2018, 1:44:02 PM3/5/18
to jenkinsc...@googlegroups.com
Dominik Bartholdi commented on Bug JENKINS-48562
 
Re: Inline Environment Variables not replaced in config file

Hey Andrew Bayer I'm using TokenMacro to expand all variables, this works fine if the pipeline job is parameterized itself, but now it seems that variables provided by the declarative pipeline are not expanded by the TokenMacro, is this correct? what can I do?

 

https://github.com/jenkinsci/config-file-provider-plugin/blob/master/src/main/java/org/jenkinsci/lib/configprovider/model/ConfigFileManager.java#L118 

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.3.0#73011-sha1:3c73d0e)
Atlassian logo

andrew.bayer@gmail.com (JIRA)

unread,
Mar 5, 2018, 2:06:03 PM3/5/18
to jenkinsc...@googlegroups.com

First, give it a try with just a Scripted Pipeline with the variables in withEnv - Declarative's environment just maps to withEnv behind the scenes. And then if it turns out that doesn't work either, we need to figure that out. =)

domi@fortysix.ch (JIRA)

unread,
Mar 6, 2018, 12:03:04 PM3/6/18
to jenkinsc...@googlegroups.com

thanks Andrew Bayer!

I now tried the following:
node{
withEnv(['dbName = "test-$\{env.BUILD_NUMBER}"', 'X_SITENAME = "HELLO"', 'X_DB_USER = "mp"', 'DOMAIN_NAME = "https://www.example.com"']) {
configFileProvider([configFile(fileId: 'settings_php', replaceTokens: true, targetLocation: "$\{dbName}/www/local.settings.php")]) {
sh "cat ${env.dbName}/www/local.settings.php"
}
}
}
 
node{
withEnv(['dbName = "test-$\{env.BUILD_NUMBER}"', 'X_SITENAME = "HELLO"', 'X_DB_USER = "mp"', 'DOMAIN_NAME = "https://www.example.com"']) {
configFileProvider([configFile(fileId: 'settings_php', replaceTokens: true, targetLocation: "$\{dbName}/www/local.settings.php")]) {
sh "cat ${dbName}/www/local.settings.php"
}
}
}
 

...unfortunate it did not work - it already fails at this:
sh "cat ${env.dbName}/www/local.settings.php"
because it can't find "dbName"

tested on:

  • jenkins 2.73.4.1 (DEV@cloud)
  • pipeline 2.4

domi@fortysix.ch (JIRA)

unread,
Mar 6, 2018, 12:04:04 PM3/6/18
to jenkinsc...@googlegroups.com
Dominik Bartholdi edited a comment on Bug JENKINS-48562
thanks [~abayer]!


I now tried the following:
{code:java}
node \ {
   withEnv(['dbName = "test-$\{env.BUILD_NUMBER}"', 'X_SITENAME = "HELLO"', 'X_DB_USER = "mp"', 'DOMAIN_NAME = "https://www.example.com"'])
\ {
      configFileProvider([configFile(fileId: 'settings_php', replaceTokens: true, targetLocation: "$\{dbName}/www/local.settings.php")])
\ {
         sh "cat $
\
{env.dbName}/www/local.settings.php"
      }
   }
}
{code}

 
{code:java}
node \ {
   withEnv(['dbName = "test-$\{env.BUILD_NUMBER}"', 'X_SITENAME = "HELLO"', 'X_DB_USER = "mp"', 'DOMAIN_NAME = "https://www.example.com"'])
\ {
      configFileProvider([configFile(fileId: 'settings_php', replaceTokens: true, targetLocation: "$\{dbName}/www/local.settings.php")])
\ {
         sh "cat $
\
{dbName}/www/local.settings.php"
      }
   }
}
{code}

 

...unfortunate it did not work - it already fails at this:
sh "cat $\{env.dbName}/www/local.settings.php"
because it can't find "dbName"

tested on:
* jenkins 2.73.4.1 (DEV@cloud)
* pipeline 2.4

jenkins@michaelpporter.com (JIRA)

unread,
Aug 18, 2018, 1:45:02 PM8/18/18
to jenkinsc...@googlegroups.com

I noticed your first example you are not calling `env.dbName` but `dbName` is that a type-o or does it not work still?

node{
   withEnv(['dbName = "test-$\{env.BUILD_NUMBER}"', 'X_SITENAME = "HELLO"', 'X_DB_USER = "mp"', 'DOMAIN_NAME = "https://www.example.com"']) {
      configFileProvider([configFile(fileId: 'settings_php', replaceTokens: true, targetLocation: "$\{dbName}/www/local.settings.php")]) {
         sh "cat ${env.dbName}/www/local.settings.php"
      }
   }
 }

I have been calling a Job to build the file, but it would be nice to get away from this and us full pipeline.

    build job: 'global-builds/drupal-build-site-test',
        parameters: [
            string(name: 'SITE_NAME', value: "${siteName}"),
            string(name: 'DATABASE_NAME', value: "${siteName.replaceAll('-','_')}"),
            string(name: 'DATABASE_USER', value: "${dbUser}"),
            string(name: 'DOMAIN_NAME', value: "${domain}"),
            [$class: 'LabelParameterValue', name: 'node', label: "${buildLabel}"]]
This message was sent by Atlassian JIRA (v7.10.1#710002-sha1:6efc396)

jenkins@michaelpporter.com (JIRA)

unread,
Aug 18, 2018, 2:39:02 PM8/18/18
to jenkinsc...@googlegroups.com

A bit of a hack, but I found a pipeline workaround. by using `envsubst`

node{
    configFileProvider([configFile(fileId: 'drupal7-test', 
        replaceTokens: false, targetLocation: "web/settings.template.php")]) {
         sh """cat web/settings.template.php
         SITE_NAME=my-db-master DATABASE_NAME=my_db_master DATABASE_USER=my_db envsubst < web/settings.template.php > web/settings.local.php
         cat web/settings.local.php
         """
      }
 }

domi@fortysix.ch (JIRA)

unread,
Jun 5, 2019, 2:48:03 AM6/5/19
to jenkinsc...@googlegroups.com
Dominik Bartholdi resolved as Fixed
 

resolved with 3.6.1

Jenkins / Bug JENKINS-48562
Change By: Dominik Bartholdi
Status: Open Resolved
Resolution: Fixed
This message was sent by Atlassian Jira (v7.11.2#711002-sha1:fdc329d)
Reply all
Reply to author
Forward
0 new messages