0

I have a Jenkinsfile that takes a bunch of params ( 50 aprox.), and other 50 for input processing:

pipeline {
    agent { label 'ansible24' }
    parameters {
            string(name: 'NAME', defaultValue: 'Nightly Valid', description: ' instance name')
    // ... x50
    }
    script {
        def filename = "configuration.yml"
        def yaml = readYaml file: filename                    
       yaml.global.name = "${params.NAME}".toString()
       // ... x50
}

Tomorrow, I will also have a validation for each field.

How could I extract this logic in separated files?

I already saw this: How do you load a groovy file and execute it

but it doesn't help a lot for the case of params and my case is not scripted.

Any idea ?

Juliatzin
  • 18,455
  • 40
  • 166
  • 325
  • did you considered using of Shared Libraries https://jenkins.io/doc/book/pipeline/shared-libraries/ ? – BigGinDaHouse May 23 '18 at 09:43
  • If you load groovy files using `load ` step they can access parameters using `params` without any additional workarounds. – Vitalii Vitrenko May 23 '18 at 09:48
  • @VitaliiVitrenko are you telling me I should let params in main file, and extract everything else in files? – Juliatzin May 23 '18 at 11:54
  • @BigGinDaHouse It is not really my use case, as I will probably not reuse my code, just want to refactor it not to have a big scary pipeline file – Juliatzin May 23 '18 at 11:55
  • I got it, but it is not necessary to reuse code for consuming shared libs, use them just for extractions – BigGinDaHouse May 23 '18 at 12:10
  • I find a lot of docs about scripted programming, but none for declarative. If I can't extract params, how could I extract a stage that make for example a single stage: sh 'rm -rf *' – Juliatzin May 23 '18 at 13:01

0 Answers0