Pipeline failing to load Properties file using the EnvInject plugin

1,148 views
Skip to first unread message

Brendan Murtagh

unread,
Oct 20, 2016, 10:52:35 PM10/20/16
to Jenkins Users
Hello,

I'm feeling stuck at the moment trying to sort this out. Hopefully ya'll are able to assist.

Situation:

We are converting a traditional Freestyle project to Pipeline. The Freestyle project has build parameters that the user kicking off the build can edit for their needs. I'm trying to figure out how to manage this Build Parameters in the Pipeline world. 

Here is what I'm currently implementing:

I have a Key/Value Properties file saved and stored in AWS S3. The format of this file is based off of the EnvInject requirements: https://en.wikipedia.org/wiki/.properties

  CLIENT_ID=ClientShortName
  LPRLISTENPORT=7201

In my first Stage, I am fetching this file using the AWS CLI from S3. (While I'm troubleshooting, I cat this file to ensure the download was successful and content is present.)
After the file has been downloaded, I am attempting to use the properties command in the Jenkinsfile to load the file (the filename is stored in a variable for flexibility:

  def deployParams = 'deploy.properties' // testing
  properties([
    [$class: 'BuildDiscarderProperty', strategy: [$class: 'LogRotator', artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '3']],
    [$class: 'RebuildSettings', autoRebuild: false, rebuildDisabled: false], [$class: 'ThrottleJobProperty', categories: [], limitOneJobWithMatchingParams: false, maxConcurrentPerNode: 0, maxConcurrentTotal: 0, paramsToUseForLimit: '', throttleEnabled: false, throttleOption: 'project'],
    [$class: 'EnvInjectJobProperty', info: [loadFilesFromMaster: false, propertiesFilePath: "${deployParams}"], keepBuildVariables: true, keepJenkinsSystemVariables: true, on: true]
  ])

The second Stage contains the code checkout. I was previously using the Git plugin, but I saw in the EnvInject Plugin that the properties aren't loaded until after the SCM checkout (I assume the git function satisfies this, but I'm not 100%). 
After the checkout, I am performing some simple validation to see if the loaded properties are available as Environment Variables as I expect.

  checkout scm
  envVars = env.getEnvironment()
  echo "${env.getEnvironment()}"
  println envVars.containsKey("LPRLISTENPORT")
  println envVars.containsKey("CLIENT_ID")

The Console Ouput from the Pipeline execution is below. A lot has been scrubbed for privacy, but here are the main points. Please let me know if further info is needed:

[Pipeline] properties
[Pipeline] stage (code checkout)
Entering stage code checkout
Proceeding
[Pipeline] echo
[BUILD_DISPLAY_NAME:#113, BUILD_ID:113, BUILD_NUMBER:113, BUILD_TAG:jenkins-pipeline-113, BUILD_URL:https:///113/, CLASSPATH:, HUDSON_HOME:/var/lib/jenkins, HUDSON_SERVER_COOKIE:c719bc37b08d7ba9, HUDSON_URL:https://jenkins/, JENKINS_HOME:/var/lib/jenkins, JENKINS_SERVER_COOKIE:c719bc37b08d7ba9, JENKINS_URL:https://jenkins/, JOB_NAME:pipeline, JOB_URL:https://pipeline/]
[Pipeline] echo
false
[Pipeline] echo
false

Any help or insight is greatly appreciated.

-Brendan

Cédric COPY

unread,
Dec 29, 2016, 12:09:22 PM12/29/16
to Jenkins Users
Hey Brendan, 

Did you sucessfully load properties with envInject plugin? I am facing the same issue. Directly declaring an environment variable is ok, but loading the properties file it from either master or from the slave, and it doesn't seems to work.

Thanks.
Reply all
Reply to author
Forward
0 new messages