Skip to content

Support environment variables in global tags and global job tags#190

Merged
luisgonzalex merged 6 commits into
masterfrom
lg/global-job-tags-envvars
Mar 24, 2021
Merged

Support environment variables in global tags and global job tags#190
luisgonzalex merged 6 commits into
masterfrom
lg/global-job-tags-envvars

Conversation

@luisgonzalex

@luisgonzalex luisgonzalex commented Mar 22, 2021

Copy link
Copy Markdown
Contributor

What does this PR do?

Add support for environment variables in global job tags as per Issue 54. Support for environment variables in the global tags field was also added. The assumption is that env vars used in these fields refer to env vars configured on the master jenkins agent.

Description of the Change

There are two cases.

  1. Freestyle jobs
  2. Pipeline jobs
  • For both of these cases, we can use EnvVars.masterEnvVars to access the environment variables
  • Both of these cases are tested via unit tests and manual testing.
  • Pipeline jobs may be ran on an agent, so this was tested manually and verified for correctness.

Alternate Designs

Possible Drawbacks

This only supports env variables that were defined on the master jenkins agent. But this seems to be fine and more practical than using the env vars on the agent(s).

Verification Process

  1. Configure env variables and global job tags on master accordingly.
  2. Configure a freestyle/pipeline project.
  3. Build the project
  4. Observe that global job tags are applied correctly.

Additional Notes

Release Notes

Review checklist (to be filled by reviewers)

  • Feature or bug fix MUST have appropriate tests (unit, integration, etc...)
  • PR title must be written as a CHANGELOG entry (see why)
  • Files changes must correspond to the primary purpose of the PR as described in the title (small unrelated changes should have their own PR)
  • PR must have one changelog/ label attached. If applicable it should have the backward-incompatible label attached.
  • PR should not have do-not-merge/ label attached.
  • If Applicable, issue must have kind/ and severity/ labels attached at least.

@luisgonzalex luisgonzalex added the changelog/Added Added features results into a minor version bump label Mar 22, 2021
@luisgonzalex luisgonzalex changed the title Support environment variables in global job tags Support environment variables in global tags and global job tags Mar 23, 2021

@FlorianVeaux FlorianVeaux left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great PR and great testing 👏

This only supports env variables that were defined on the master jenkins agent. But this seems to be fine and more practical than using the env vars on the agent(s).

Let's add a comment on the jenkins UI and on the ReadMe that explains that env vars are supported for global tags and global job tags but that they refer to env vars of the controller (i.e master).

@github-actions github-actions Bot added the documentation Documentation related changes label Mar 24, 2021
@luisgonzalex
luisgonzalex merged commit 6a92656 into master Mar 24, 2021
@luisgonzalex
luisgonzalex deleted the lg/global-job-tags-envvars branch March 24, 2021 15:22
@sukanyasuresh

Copy link
Copy Markdown

Hi @luisgonzalex
I am currently using the latest version of this plugin and for some reason, I am not able to get the actual value for the env variable substituted.
This is my value configured for the global job name tags:

jobA, label:$LABEL

The value of this tag is always _label

What am I missing here?

@luisgonzalex

Copy link
Copy Markdown
Contributor Author

Hi @sukanyasuresh
Couple of things you may be missing.

  • Make sure that the env var LABEL is defined in your shell resource file. It should be defined on the same machine that is running the jenkins app.
  • Another issue may be defining the env variable after you have initiated the jenkins application. You may want to restart jenkins and run source ~/path/to/shell_resource_file so your shell has the newly defined env vars.

Hope this helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/Added Added features results into a minor version bump documentation Documentation related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants