Issue
The Config File Provider Plugin isn’t only for Maven jobs. You can define a custom config file of any type. Here we push a npmrc file to your NodeJS build.
Environment
-
CloudBees CI (CloudBees Core) on modern cloud platforms - Managed controller
-
CloudBees CI (CloudBees Core) on modern cloud platforms - Operations Center
-
CloudBees CI (CloudBees Core) on traditional platforms - Client controller
-
CloudBees CI (CloudBees Core) on traditional platforms - Operations Center
-
CloudBees Jenkins Enterprise
-
CloudBees Jenkins Enterprise - Managed controller
-
CloudBees Jenkins Enterprise - Operations center
Resolution
-
Go to
Manage Jenkins, thenManaged Filesand selectAdd a new Config -
Select
Custom fileand clickSubmit -
Name the config file
npmrcwith Content
npm_config_registry=localhost:1234 npm_other_var="some_value"
and click Submit to save
-
After saving you should see

-
Create a Pipeline job Note:
fileIdassociates with the custom config file you have just created Note:variableallows you to retrieve the content as an environment variable
node ('LINUX_GENERAL') {
stage ('build') {
configFileProvider([configFile(fileId: 'c9f8086f-0820-49ff-a66d-262bcaac7aac', variable: 'npm_config_registry')]) {
// some block
echo " =========== ^^^^^^^^^^^^ Reading config from pipeline script "
sh "cat ${env.npm_config_registry}"
echo " =========== ~~~~~~~~~~~~ ============ "
}
}
}
-
Notice output
Started by user Administrator
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node
Running on ssh-agent in /home/jenkins/299d3ab2/workspace/test-pipeline
[Pipeline] {
[Pipeline] stage
[Pipeline] { (build)
[Pipeline] configFileProvider
provisioning config files...
copy managed file [npmrc] to file:/home/jenkins/299d3ab2/workspace/test-pipeline@tmp/config7635493890434238192tmp
[Pipeline] {
[Pipeline] echo
=========== ^^^^^^^^^^^^ Reading config from pipeline script
[Pipeline] sh
+ cat /home/jenkins/299d3ab2/workspace/test-pipeline@tmp/config7635493890434238192tmp
npm_config_registry=localhost:1234
npm_other_var="some_value"
[Pipeline] echo
=========== ~~~~~~~~~~~~ ============
[Pipeline] }
Deleting 1 temporary files
[Pipeline] // configFileProvider
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS