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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Idan Adar
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 [hidden email].
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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

stephenconnolly
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 <[hidden email]> 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 [hidden email].
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.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CA%2BnPnMyR32isH7tKZ%2BvTcR1osiaBXR9dmWftaMARwMw0Qb%2B4zg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Idan Adar
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 <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="dNnAPaj0AAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">id...@...> 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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="dNnAPaj0AAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/jenkinsci-users/98e36806-f4b9-4b8d-964a-81ee0f71a66d%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/98e36806-f4b9-4b8d-964a-81ee0f71a66d%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/98e36806-f4b9-4b8d-964a-81ee0f71a66d%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/jenkinsci-users/98e36806-f4b9-4b8d-964a-81ee0f71a66d%40googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/6c1ec535-68e5-4b77-a46d-a3b8a67d958d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

stephenconnolly
Parameterized job. that will expose the parameter. you can have the parameter be a drop-down with the two clusters (and even nice names)

On 15 June 2017 at 06:12, Idan Adar <[hidden email]> wrote:
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 <[hidden email]> 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.
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.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/6c1ec535-68e5-4b77-a46d-a3b8a67d958d%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CA%2BnPnMzjHyXgi5Xkh1B_SC7BL3pHRRx%3Dmw2t%2BpVELO87wefjEQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Idan Adar
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

On 15 Jun 2017, at 16:20, Stephen Connolly <[hidden email]> wrote:

Parameterized job. that will expose the parameter. you can have the parameter be a drop-down with the two clusters (and even nice names)

On 15 June 2017 at 06:12, Idan Adar <[hidden email]> wrote:
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 <[hidden email]> 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.
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.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/6c1ec535-68e5-4b77-a46d-a3b8a67d958d%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CA%2BnPnMzjHyXgi5Xkh1B_SC7BL3pHRRx%3Dmw2t%2BpVELO87wefjEQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/B9160269-FBDE-4AFE-A8C3-290DAF5948C5%40adar.me.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Idan Adar
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/faea6e95-baac-4e08-91dc-48ba7660c33d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

stephenconnolly
yep

On 15 June 2017 at 09:18, Idan Adar <[hidden email]> 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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/faea6e95-baac-4e08-91dc-48ba7660c33d%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CA%2BnPnMz6HaE_F7Ys3_Sd61d6BOqrk13mE62tL6_XxF1A2O%2BYfg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

stephenconnolly

On 15 June 2017 at 09:28, Stephen Connolly <[hidden email]> wrote:
yep

On 15 June 2017 at 09:18, Idan Adar <[hidden email]> 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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/faea6e95-baac-4e08-91dc-48ba7660c33d%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.


--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CA%2BnPnMyuMNfBwrhmFWTgSrycMBM60%3D%2B51GjCvi2-0vHYxZwJww%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Idan Adar
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

--
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 [hidden email].
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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

stephenconnolly

On Thu 15 Jun 2017 at 17:44, Idan Adar <[hidden email]> 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 [hidden email].
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

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CA%2BnPnMy7Lc4Q577q3_vCWyqCPWGx_yY3qUkJOGt4%3DaA08L7dNg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Idan Adar
I forgot about parameters option in a Jenkinsfile... thanks.

On Thursday, June 15, 2017 at 8:12:15 PM UTC+3, Stephen Connolly wrote:

On Thu 15 Jun 2017 at 17:44, Idan Adar <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="RHjgsmUCAQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">id...@...> 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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="RHjgsmUCAQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/jenkinsci-users/67314e16-6ae2-4c93-84ed-b76b5d46f0de%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/67314e16-6ae2-4c93-84ed-b76b5d46f0de%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/67314e16-6ae2-4c93-84ed-b76b5d46f0de%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/jenkinsci-users/67314e16-6ae2-4c93-84ed-b76b5d46f0de%40googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.
--
Sent from my phone

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/711fed79-4222-47a5-8014-58c62cd39576%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...