Environment Variables in Jenkins Plugin

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Environment Variables in Jenkins Plugin

Sourabh Jain
Hi Team,

How Can I get the Environment Variables that are created in a Jenkins Pipeline.

    environment {
        ENV_V_1 = "SASbv"
    }

For now when I try to use 

EnvVars environment = run.getEnvironment(listener);

It fetches only the Environment variables attached with the Jenkins Job.

Pointer to any code or link will be helpful.

Thanks,
Sourabh Jain
Maintainer - sumologic-publisher plugin

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" 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-dev/a84644ef-21ba-43e7-a36a-f33d9386e431n%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Environment Variables in Jenkins Plugin

Jesse Glick-4
On Mon, Aug 31, 2020 at 8:44 AM Sourabh Jain <[hidden email]> wrote:
> How Can I get the Environment Variables that are created in a Jenkins Pipeline.

If you mean from within a Pipeline step, you should use

stepContext.get(EnvVars.class)

which will look up variables defined in a particular context.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" 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-dev/CANfRfr0Z%3DaLD%3DKiLD9WKbUZJ%2BVFHmugy8JEG8DL8Wc-nZrMjvA%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: Environment Variables in Jenkins Plugin

Sourabh Jain
Thanks for a quick response.

So the context is lost after the job is completed..rgt.

Thus, running "run.getEnvironment(listener);" does not give all the environment  variables when the job is completed and we try to fetch the code.

On Mon, Aug 31, 2020 at 7:49 PM Jesse Glick <[hidden email]> wrote:
On Mon, Aug 31, 2020 at 8:44 AM Sourabh Jain <[hidden email]> wrote:
> How Can I get the Environment Variables that are created in a Jenkins Pipeline.

If you mean from within a Pipeline step, you should use

stepContext.get(EnvVars.class)

which will look up variables defined in a particular context.

--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-dev/CDKvVuClyJk/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-dev/CANfRfr0Z%3DaLD%3DKiLD9WKbUZJ%2BVFHmugy8JEG8DL8Wc-nZrMjvA%40mail.gmail.com.


--
Best Regards,
Sourabh Jain
8408019626
Integration Engineer, APP DEV team,

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" 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-dev/CACHaJQQG1NvEBStzE-6Mmu4S5Zc0f6achGLh%2BUbHB2RV2UaK9g%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: Environment Variables in Jenkins Plugin

Sourabh Jain
Also, is there a class which we can use, extend or implement which can be run by default for each stage in a Jenkins pipeline(without modifying the pipeline)?

On Mon, Aug 31, 2020 at 8:29 PM Sourabh Jain <[hidden email]> wrote:
Thanks for a quick response.

So the context is lost after the job is completed..rgt.

Thus, running "run.getEnvironment(listener);" does not give all the environment  variables when the job is completed and we try to fetch the code.

On Mon, Aug 31, 2020 at 7:49 PM Jesse Glick <[hidden email]> wrote:
On Mon, Aug 31, 2020 at 8:44 AM Sourabh Jain <[hidden email]> wrote:
> How Can I get the Environment Variables that are created in a Jenkins Pipeline.

If you mean from within a Pipeline step, you should use

stepContext.get(EnvVars.class)

which will look up variables defined in a particular context.

--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-dev/CDKvVuClyJk/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-dev/CANfRfr0Z%3DaLD%3DKiLD9WKbUZJ%2BVFHmugy8JEG8DL8Wc-nZrMjvA%40mail.gmail.com.


--
Best Regards,
Sourabh Jain
8408019626
Integration Engineer, APP DEV team,



--
Best Regards,
Sourabh Jain
8408019626
Integration Engineer, APP DEV team,

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" 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-dev/CACHaJQQ9D4c1R4dtTpUqSt1jSLqpYxQ-VAk6cEgz7qin0pwkxg%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: Environment Variables in Jenkins Plugin

Jesse Glick-4
On Mon, Aug 31, 2020 at 11:05 AM Sourabh Jain <[hidden email]> wrote:
> is there a class which we can use, extend or implement which can be run by default for each stage in a Jenkins pipeline(without modifying the pipeline)?

https://javadoc.jenkins.io/plugin/workflow-api/org/jenkinsci/plugins/workflow/flow/GraphListener.html

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" 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-dev/CANfRfr1y0-V3freUNpf05r6Dn7%2BgTfGCYb2HX3NccvyFvqGTWw%40mail.gmail.com.