The initial release for the pipeline library already contained the pattern-matching mechanism which is able to provide scm-url related settings for
- credentials
- maven settings
- etc.
Over the time the configuration via json and the strict one-to-one relation ship between a pattern and configuration lead to some frustration and administrative overhead.
Also the SCM_URL approach did not fit in all scenarios. So we introduced the Fully-Qualified Job Name (FQJN) approach
That's why the GenericConfig
was introduced.
The generic configuration is based upon a yaml format and allows you to specify 1-N patterns for the pattern-matching mechanism.
- patterns:
- multi-pattern1
- multi-pattern2
id: "multi-pattern-id"
config:
key: value
# ...
This structure was kept due to legacy issues. The Multi-pattern variant should be preferred.
- pattern: single-pattern
id: "single-pattern-id"
config:
key: value
These yaml files can be placed in the resources
folder of your
pipeline-library configuration SCM Project.
E.g. resources/jenkins-pipeline-library/config/notify/mattermost.yaml
The general concept of the pattern matching is documented in PatternMatching.
In this pipeline library we use two sources for the pattern, which are documented in the following sections.
In this variant we are using SCM_URL to find an appropriate configuration item from a list.
This mechanism is for example used in:
Example
String scmUrl = getScmUrl()
Map yamlConfig = genericConfig.load('resources/jenkins-pipeline-library/config/notify/mattermost.yaml', scmUrl, 'notifyMattermost')
In this variant we are using a combination of the Jenkins JOB_NAME
and
the GIT_BRANCH
to find an appropriate configuration item from a list.
For example the JOB_NAME
is folder/subfolder/my_compile_job
and the
GIT_BRANCH
is origin/feature/my-branch
then the FQJN is
folder/subfolder/my_compile_job@feature/my-branch
.
Please note that we are stripping off the origin/
from the
GIT_BRANCH
.
💡 It is highly recommended to use the
checkoutScm
step from the pipeline library,
because this step is taking care of setting the correct GIT_BRANCH
!
This mechanism is for example used in:
When using FQJN as pattern matching search value you for example include only jobs that are building the master branch:
patterns:
- ^folder\/subfolder\/.*@master
You can also exclude jobs that are building feature branches:
patterns:
- ^folder\/subfolder\/.*@(?!feature)
💡 For your convenience a step is available: genericConfig.
import io.wcm.devops.jenkins.pipeline.config.GenericConfigUtils
GenericConfigUtils genericConfigUtils = new GenericConfigUtils(this)
String search = genericConfigUtils.getFQJN()
Map yamlConfig = genericConfig.load('resources/jenkins-pipeline-library/config/notify/mattermost.yaml', getScmUrl(), 'notifyMattermost')