Can a Jenkins global variable be used inside running code as part of a job?

20 views
Skip to first unread message

Idan Adar

unread,
Jun 15, 2017, 8:19:23 AM6/15/17
to Jenkins Users
Currently I have in a node project a .json file with certain values.
Is it possible to externalize these values into a Jenkins global variable and then consume these properties in my code?

Stephen Connolly

unread,
Jun 15, 2017, 9:00:27 AM6/15/17
to jenkins...@googlegroups.com
It looks like you are trying to write a build script in pipeline...


I would think twice if that is actually what you are trying to do.

Write your build script to be independent of Jenkins. That lets you test thing from the command line.

Pipeline is the glue to wire it all together at the end (same goes for non-pipeline job types, except it is harder to fall into the trap and hence less likely... but it can still happen)


On 15 June 2017 at 05:19, Idan Adar <id...@adar.me> wrote:
Currently I have in a node project a .json file with certain values.
Is it possible to externalize these values into a Jenkins global variable and then consume these properties in my code?

--
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-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/98e36806-f4b9-4b8d-964a-81ee0f71a66d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Idan Adar

unread,
Jun 15, 2017, 9:12:19 AM6/15/17
to Jenkins Users
Here's the situation:

I have 2 clusters, each with its own unique URL, that do end-2-end testing.
The code that does the tests is the same. It basically goes through a set of actions performed on a cluster.

I have a job that basically does npm test which starts the process.
Now I'd like to use the same code and the same job to be able to run the test for the second cluster.

The URL of the cluster is inside the code. So without a way to change the URL in some way, I can't run the tests on the second cluster.
Options thus far:

1. Use branches, one for each, but that means updating the tests twice...
2. Use external variable to update the URL value during runtime
3. Find out the job name during runtime and then use a different config file during runtime.

3 is a new option that I'd like to explore. Is there a way to retrieve the job name during a job runtime?

On Thursday, June 15, 2017 at 4:00:27 PM UTC+3, Stephen Connolly wrote:
It looks like you are trying to write a build script in pipeline...


I would think twice if that is actually what you are trying to do.

Write your build script to be independent of Jenkins. That lets you test thing from the command line.

Pipeline is the glue to wire it all together at the end (same goes for non-pipeline job types, except it is harder to fall into the trap and hence less likely... but it can still happen)

On 15 June 2017 at 05:19, Idan Adar <id...@adar.me> wrote:
Currently I have in a node project a .json file with certain values.
Is it possible to externalize these values into a Jenkins global variable and then consume these properties in my code?

--
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.

Stephen Connolly

unread,
Jun 15, 2017, 9:21:13 AM6/15/17
to jenkins...@googlegroups.com
Parameterized job. that will expose the parameter. you can have the parameter be a drop-down with the two clusters (and even nice names)

To unsubscribe from this group and stop receiving emails from it, 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/6c1ec535-68e5-4b77-a46d-a3b8a67d958d%40googlegroups.com.

Idan Adar

unread,
Jun 15, 2017, 11:18:01 AM6/15/17
to jenkins...@googlegroups.com
Thanks. I'll need it to be two jobs as the first cluster has a 3 runs scheduled and the second one shouldn't be scheduled. I'll give it a try.

Sent from my iPhone
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/1Cfq4PzoPsM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CA%2BnPnMzjHyXgi5Xkh1B_SC7BL3pHRRx%3Dmw2t%2BpVELO87wefjEQ%40mail.gmail.com.

Idan Adar

unread,
Jun 15, 2017, 12:18:55 PM6/15/17
to Jenkins Users
Question:

It seems that $CHANGE_ID and $CHANGE_URL are not available in a pipeline job but are available in a multibranch job?

Stephen Connolly

unread,
Jun 15, 2017, 12:28:45 PM6/15/17
to jenkins...@googlegroups.com
yep

On 15 June 2017 at 09:18, Idan Adar <id...@adar.me> wrote:
Question:

It seems that $CHANGE_ID and $CHANGE_URL are not available in a pipeline job but are available in a multibranch job?

--
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-users+unsubscribe@googlegroups.com.

Stephen Connolly

unread,
Jun 15, 2017, 12:29:31 PM6/15/17
to jenkins...@googlegroups.com

Idan Adar

unread,
Jun 15, 2017, 12:44:17 PM6/15/17
to Jenkins Users
Well that's a deadlock... I need both those variables and the parameter provided to me via parametrized build...
parametrized build is available in pipeline but not multibranch

Stephen Connolly

unread,
Jun 15, 2017, 1:12:15 PM6/15/17
to jenkins...@googlegroups.com
On Thu 15 Jun 2017 at 17:44, Idan Adar <id...@adar.me> wrote:
Well that's a deadlock... I need both those variables and the parameter provided to me via parametrized build...
parametrized build is available in pipeline but not multibranch

If can define the parameters from your Jenkinsfile

An alternative is to use a different Jenkinsfile (in a different repo) for the deployment 


--
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/67314e16-6ae2-4c93-84ed-b76b5d46f0de%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
--
Sent from my phone

Idan Adar

unread,
Jun 16, 2017, 11:35:26 AM6/16/17
to Jenkins Users
I forgot about parameters option in a Jenkinsfile... thanks.
Reply all
Reply to author
Forward
0 new messages