Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add config file for config file provider plugin with groovy script in jenkins

I am using Job DSL in Jenkins. There is a seed job that generates some files that should be shared across other jobs that could run on different nodes. If the files were not generated, the config files provider plugin could be used for this task. However I need the files to be dynamic so that no Jenkins UI interaction is needed.

Is it possible to add a file to the plugin with a groovy script?

The only other option I could think of was to record the UI interaction and let a script replay it with modified data. In case of a more secured Jenkins this would also require to get authentication and CSRF tokens right.

like image 490
Peter Lutz Avatar asked Jan 04 '23 06:01

Peter Lutz


2 Answers

You can use Job DSL to create config files that are managed by the Config File Provider plugin:

configFiles {
    customConfig {
        id('one')
        name('Config 1')
        comment('lorem')
        content('ipsum')
        providerId('???')
    }
}

See https://github.com/jenkinsci/job-dsl-plugin/wiki/Job-DSL-Commands#config-file

like image 179
daspilker Avatar answered Jan 13 '23 15:01

daspilker


When you are using job-dsl you can read in data from anywhere that the Groovy runtime can access.

You could store shared config in a hard coded variable in your script itself.

You could inject the data via a Jenkins parameter to your seed job.

You could retrieve the data from a file in the git repo where your store your seed job.

You could retrieve the data from a database, REST API.

etc etc.

like image 29
Rob Kielty Avatar answered Jan 13 '23 15:01

Rob Kielty