[HAP-333] Environment variables not passed to Artifactory Created: 12/Aug/12  Updated: 13/Feb/15  Resolved: 30/Jan/13

Status: Resolved
Project: Jenkins Artifactory Plug-in
Component/s: None
Affects Version/s: None
Fix Version/s: 2.1.4

Type: Bug Priority: Critical
Reporter: Michael Huettermann Assignee: Shay Yaakov (Inactive)
Resolution: Fixed Votes: 0
Labels: None


 Description   

In Jenkins, as a "Pre Steps", I inject an environment variable via property file. The property file is generated during build time. As the "Post-build Actions", I deploy artifacts to Artifactory. Although I check "Include all environment variables", my environment variable is not listed in Artifactory's "Environment" panel for builds. In Jenkins, I've also added the environment variable in "Deployment properties" under the section "Deploy maven artifacts". But in Artifactory, the variable was not resolved in the Repository Browser > "Metadata" of the deployed artifact. The property key is listed but the value is still the variable (e.g. $value), and not the concrete value.



 Comments   
Comment by Michael Huettermann [ 21/Aug/12 ]

A concrete use case:

"Pre Steps" => "Execute shell"
echo values=100,101,102 > data.properties

"Inject environment variables to the build process"
Properties File Path => data.properties
(dummy file must be present in the workspace before build time, e.g. through checkout out from VCS)

Neither "Deploy artifacts to Artifactory" => "Deployment properties" nor "Capture and publish build info" transports my $values to Artifactory. I've e.g. tried to set "Deployment properties" such as buildInfo.property.values=$values;artifactory.deploy.values=$values, without success.

In Artifactory, it would be helpful to have the $values attached to both, the published artifacts as well as the build info.

Comment by Michael Huettermann [ 28/Nov/12 ]

Strill trying to forward newly set environment parameters from Jenkins to Artifactory.

A different approach also does not work:

In a Jenkins M2 build, a pre build step is introduced to compute and set a Jenkins environment variable. The Jenkins pre build step is based on an own Jenkins plugin that extends "hudson.tasks.Builder".
EnvVars envVars = build.getEnvironment(listener);
envVars.put(aKey, aValue);

This means the aKey/aValue pair is not available when the build job starts but is set during the build run. I can output the newly set variable in other build steps successfully. Unfortunately, the new set environment variable is not passed to Artifactory. In Jenkins, the job is configured to include all environment variables.

I think it would be even more consistent to collect all Jenkins environment variables before these data are forwarded to Artifactory.

Comment by Yossi Shaul [ 20/Jan/13 ]

Native Maven 3 builds won't work if the resolver is not configured.

Comment by Shay Yaakov (Inactive) [ 28/Jan/13 ]

When using Native Maven 3, you must check "Resolve artifacts from Artifactory" in order to properly resolve env vars from plugins such as EnvInject.

Comment by Zageyiff [ 18/Nov/14 ]

Hello, I'm facing this issue.

I choose a new item "Build a maven project"
I configured the "Resolve artifacts from Artifactory"
And "Deploy artifacts to Artifactory" as post build action

I'm adding properties to "Deployment properties" that were generated in a pre build shell script and loaded in a pre build envinject plugin

These properties don't get resolved, and end up in Artifactory as key=${value}

Jenkins: 1.580.1
Artifactory plugin: 2.2.4
Maven plugin: 2.5
Maven: 3.1.1

Any help is appreciated

Comment by Avi Amsalem [ 01/Jan/15 ]

Someone successed ? or it still unresolved?
to me it's not working.

Plugin version 2.2.5
Jenkins 1.5.7.2
EnvInject plugin version 1.9.0

Please Advice ASAP!.

Comment by William Duncan [ 13/Feb/15 ]

I too am experiencing the same or a similar issue. Environment variables injected as a pre-build step are not resolved in the "Deployment Properties" section Semicolon-separated list of properties to attach to all deployed artifacts in addition to the default ones, rather the literal variable content is passed to Artifactory as a property value.

For example:

Setting an Artifactory Deployment Properties value of revision=${PRODUCT_VERSION}.${BUILD_NUMBER}, where PRODUCT_VERSION is an injected environment variable, and is used successfully during the build phase, the property value populated in Artifactory is something similar to the following for each successive build/deploy:

Property Key Property Value
revision ${PRODUCT_VERSION}.10
revision ${PRODUCT_VERSION}.11
revision ${PRODUCT_VERSION}.12



Artifactory Plugin Version: 2.2.7
Jenkins Version: 1.580.3
Environment Injector Plugin: 1.9.0

Generated at Tue Jan 21 12:55:07 UTC 2020 using JIRA 7.6.16#76018-sha1:9ed376192612a49536ac834c64177a0fed6290f5.