Skip to content

Commit ab36352

Browse files
author
R. Tyler Croy
authored
Merge pull request jenkinsci#66 from mramanathan/cfgfile_provider
configFile Provider plugin usage
2 parents 3a22aaa + 4cfa46e commit ab36352

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[configFile Provider plugin] (https://plugins.jenkins.io/config-file-provider) enables provisioning of various types of configuration files. Plugin works in such a way as to make the configuration available for the entire duration of the build across all the build agents that are used to execute the build.
2+
3+
Common scenarios that demand the usage of configuration files:
4+
5+
- Provide properties that can be consumed by the build tool
6+
- Global settings that override local settings
7+
- Details of credentials needed to access repos
8+
- Inputs to generate binary images that need to be tailored to specific architectures
9+
10+
The example shows simple usage of configFile Provider plugin and howto access it's contents.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!groovy
2+
3+
node {
4+
stage('configFile Plugin') {
5+
6+
// 'ID' refers to alpha-numeric value generated automatically by Jenkins.
7+
// This code snippet assumes that the config file is stored in Jenkins.
8+
9+
// help to assign the ID of config file to a variable, this is optional
10+
// as ID can be used directly within 'configFileProvider' step too.
11+
def mycfg_file = '<substitute-alpha-numeric-value-cfgfille-here-within-quotes>'
12+
13+
// whether referencing the config file as ID (directly) or via user-defined
14+
// variable, 'configFileProvider' step enables access to the config file
15+
// via 'name' given for the field, 'variable:'
16+
configFileProvider([configFile(fileId: mycfg_file, variable: 'PACKER_OPTIONS')]) {
17+
echo " =========== ^^^^^^^^^^^^ Reading config from pipeline script "
18+
sh "cat ${env.PACKER_OPTIONS}"
19+
echo " =========== ~~~~~~~~~~~~ ============ "
20+
21+
// Access to config file opens up other possibilities like
22+
// passing on the configuration to an external script for other tasks, like,
23+
// for example, to set generic options that can be used for generating
24+
// binary images using packer.
25+
echo " =========== ^^^^^^^^^^^^ Reading config via Python... "
26+
sh "python build_image.py ${env.PACKER_OPTIONS}"
27+
echo " =========== ~~~~~~~~~~~~ ============ "
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)