Parameterized build driven by Jenkinsfile

656 views
Skip to first unread message

Craig Barr

unread,
Aug 3, 2017, 12:24:34 AM8/3/17
to Jenkins Users
In Jenkins you can select "This project is parameterized" and add parameters. My question is simple:
Can this parameter metadata be populated by an alternative version-controlled source?

For example, can I define parameter definitions in my Jenkinsfile so that when I click Build Now it will populate the parameters from this source?
If this is not possible, are they any other suggestions for addressing such a requirement?

Thanks!

Jacob Larsen

unread,
Aug 3, 2017, 4:13:54 AM8/3/17
to jenkins...@googlegroups.com

Yes, kind of...

The parameters are hidden in the "properties" structure. They will be applied to the job when it runs, meaning that the first run will not have these parameters defined. If you make your Jenkinsfile robust for undefined parameters, it should be doable, just remember that they will apply to the second build.

/Jacob

--
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/eb7dca33-81d0-4b35-9045-0ab521327109%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alex Marcon

unread,
Aug 3, 2017, 1:27:44 PM8/3/17
to Jenkins Users
That's right... to define, it is something like:

    parameters {
        string(name: 'bld', defaultValue: 'full', description: '')
        string(name: 'branch', defaultValue: 'dev', description: '')
    }

you may load some properties from a file and use those variables for defaultValue...

AM

Craig Barr

unread,
Aug 9, 2017, 4:07:40 AM8/9/17
to Jenkins Users
Thanks Jacob and Alex!

Which version of Jenkins does this work for you on?
I've tried with the following Jenkinsfile on 2.46.1 but no matter how many times I ran, the parameters never showed up in the console.

parameters {

   string(name: 'bld', defaultValue: 'full', description: '')

   string(name: 'branch', defaultValue: 'dev', description: '')

}


node {

   if (getBinding().hasVariable("bld")) {

      echo "SET"

   } else {

      echo "NOTSET"

Jacob Larsen

unread,
Aug 9, 2017, 3:41:09 PM8/9/17
to jenkins...@googlegroups.com

Try this:

properties([
    parameters([
        string(name: 'bld', defaultValue: 'full', description: ''),
        string(name: 'branch', defaultValue: 'dev', description: '')
    ])
])

/Jacob

R. Tyler Croy

unread,
Aug 9, 2017, 5:26:14 PM8/9/17
to jenkins...@googlegroups.com
(replies inline)

On Wed, 02 Aug 2017, Craig Barr wrote:

> In Jenkins you can select "This project is parameterized" and add
> parameters. My question is simple:
> Can this parameter metadata be populated by an alternative
> version-controlled source?
>
> For example, can I define parameter definitions in my Jenkinsfile so that
> when I click Build Now it will populate the parameters from this source?
> If this is not possible, are they any other suggestions for addressing such
> a requirement?


My pal Liam created a screencast on this topic recently:
https://www.youtube.com/watch?v=5_tvlaIeQUQ&feature=youtu.be

See also: https://jenkins.io/doc/book/pipeline/jenkinsfile/#parameters


- R. Tyler Croy

------------------------------------------------------
Code: <https://github.com/rtyler>
Chatter: <https://twitter.com/agentdero>
xmpp: rty...@jabber.org

% gpg --keyserver keys.gnupg.net --recv-key 1426C7DC3F51E16F
------------------------------------------------------
signature.asc

Craig Barr

unread,
Aug 10, 2017, 2:56:50 AM8/10/17
to jenkins...@googlegroups.com
Thanks Jacob. That worked exactly as I would expect!

To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/oRhJRoBgWfc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/0978cc69-5cbe-6737-a7dc-802fc3dc1511%40larsen.net.
Reply all
Reply to author
Forward
0 new messages