Reputation: 53
I want to have common environment variables through all my pipelines. I am using a Shared Library, so I was wondering, how can I put constant values into a shared library and use it in any pipeline.
Is there a way to put it in the src
directory, or vars
, and use it in a pipeline without creating an object in a pipeline? I tried both but was unsuccessful.
Thank you and best regards,
Upvotes: 0
Views: 700
Reputation: 1
To use global values in your jenkins pipelines, you can makes use of global envs or configuration files in /resources
These are configured on a jenkins level, and can be accessed from any pipeline on the instance (regardless of the use of a shared library)
This is answered in detail here https://stackoverflow.com/a/41235654/22666765
A config file can be added (of any format) to the /resources folder in your shared library.
This can then be read using the libraryResource
function provided by Jenkins https://www.jenkins.io/doc/pipeline/steps/workflow-cps-global-lib/#libraryresource-load-a-resource-file-from-a-shared-library
Once the file is read, your values can be parsed & loaded into variables on the pipeline level
Upvotes: 0