How to use a custom config file provider

Article ID:360040961031
2 minute readKnowledge base


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.


  1. Go to Manage Jenkins, then Managed Files and select Add a new Config

  2. Select Custom file and click Submit

  3. Name the config file npmrc with Content

01 create npmrc config file

and click Submit to save

  1. After saving you should see 02 view npmrc config file

  2. Create a Pipeline job Note: fileId associates with the custom config file you have just created Note: variable allows 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 " =========== ~~~~~~~~~~~~ ============ "
  1. Notice output

Started by user Administrator
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node
Running on ssh-slave 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
[Pipeline] echo
 =========== ~~~~~~~~~~~~ ============
[Pipeline] }
Deleting 1 temporary files
[Pipeline] // configFileProvider
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS