Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional loops in Job DSL

I'm taking the build type i.e either Maven Job or Freestyle job as an input parameter (using the build parameterized plugin) and based on the input condition create the corresponding Job

My input parameter: "maven" (to create Maven job) , else block for freestyle Job.

if(params[build_type]=="maven"){
    mavenJob('example') {
        using(template_job)
          scm { 
            svn {
              location(svn_url)
            }
          } 
       } 
}
freeStyleJob('example') {
        using(template_job)
          scm { 
            svn {
              location(svn_url)
            }
          } 
       } 

I'm facing the following error message and I'm very new to groovy so please excuse. Looking forward for any suggestions.Thanks.

Processing provided DSL script ERROR: (script, line 1) No such property: params for class: script

like image 520
Goku Avatar asked Feb 03 '17 11:02

Goku


People also ask

What is DSL job in Jenkins?

Jenkins job DSL is a plugin that allows us to define jobs in programmatic form with minimal effort. DSL stands for Domain Specific Language. You can describe your jobs in Jenkins using a Groovy Based Language. Groovy-- It's similar to java but simpler because it's much more dynamic. It''s Scripting Language.


1 Answers

The Job DSL script inherits the build parameters as variables in your Job DSL. So if you have a parameter named build_type, you can use it as a variable.

if (build_type == "maven") {
    mavenJob('example') {
        using(template_job)
        scm { 
            svn {
                location(svn_url)
            }
        } 
    } 
}

See: User Power Moves: Parameterized Seed Job

like image 92
Highway of Life Avatar answered Nov 15 '22 06:11

Highway of Life