Conditional configuration with the Job DSL

40 views
Skip to first unread message

Nick Stolwijk

unread,
Oct 6, 2015, 3:09:45 AM10/6/15
to jenkins...@googlegroups.com
I'm trying to rebuild my Jenkins jobs through the Job DSL. I have found a lot of documentation and examples, but none about conditional configuration.

I have the following job input:

projects {
  componentA {
  }
  componentB {
  }
}

Now I am trying to create jobs for this:

def createUT(name, data) {
  mavenJob("${name}_UT") {
    description("Generated. Don't edit!")
    scm { 
//      git {
//        remote {
//          url(data.git_url)
//          credentials('xxxxx-xxxx')
//        }
//        createTag(false)
//      }
        svn(data.svn-url) {
          it / locations / 'hudson.scm.SubversionSCM_-ModuleLocation' / credentialsId << 'xxxxx-xxxx'      
        }
    } 

How can I create the git or the svn part, based on which variable is declared?

Hope someone can help.

Nick Stolwijk

~~~ Try to leave this world a little better than you found it and, when your turn comes to die, you can die happy in feeling that at any rate you have not wasted your time but have done your best ~~~

Lord Baden-Powell

Baptiste Mathus

unread,
Oct 6, 2015, 3:20:13 AM10/6/15
to jenkins...@googlegroups.com
Well, Job DSL is actually Groovy code. So something like the following should work:

 scm { 
   if(data.git_url) {
      git {
        remote {
          url(data.git_url)
          credentials('xxxxx-xxxx')
        }
        createTag(false)
      }
     }
     else if(data.svn-url) {
        svn(data.svn-url) {
          it / locations / 'hudson.scm.SubversionSCM_-ModuleLocation' / credentialsId << 'xxxxx-xxxx'      
        }
     }
     else {
       // crash the build or something if none was found?
     }

Cheers

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAA9S6i4Df6ENZ55Qmqx7aUYGmNFexFJ3opmeeJC72dxQpf5AFA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.



--
Baptiste <Batmat> MATHUS - http://batmat.net
Sauvez un arbre,
Mangez un castor !

Nick Stolwijk

unread,
Oct 6, 2015, 4:26:44 AM10/6/15
to jenkins...@googlegroups.com
Doh... that is simpler than I thought. :D I couldn't find any examples in the various Job DSL configurations I had found.

Thanks for the help!

Nick Stolwijk

~~~ Try to leave this world a little better than you found it and, when your turn comes to die, you can die happy in feeling that at any rate you have not wasted your time but have done your best ~~~

Lord Baden-Powell

Victor Martinez

unread,
Oct 6, 2015, 10:59:00 AM10/6/15
to Jenkins Users
Nick,

 There is also another google group you might find useful:

Cheers
Reply all
Reply to author
Forward
0 new messages