Scripts in environment stage

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

Scripts in environment stage

Ven H
Can we have script block or credential block to perform some logic inside the environment stage in Jenkinsfile? When I tried, it kept throwing errors saying only variable=value kind of expressions are allowed inside the environment stage.
I want to read a Yaml file inside the environment stage since it is at the very beginning, to get some variable values. Please help.

Regards,
Venkatesh

--
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/CAPp28eqAKiOCd%2BN5nYnkMCtytQVXCyo1KFg8KJ2Q-mtuWQkENA%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: Scripts in environment stage

Yves Schumann
Hi Ven

Am 08.12.2020 um 18:56 schrieb Ven H:
> Can we have script block or credential block to perform some logic
> inside the environment stage in Jenkinsfile?

I'm doing such things without issues. Some examples:

GIT_COMMIT_SHORT = sh(
        script: "printf \$(git rev-parse --short ${GIT_COMMIT})",
        returnStdout: true
)
CURRENT_DATE = sh(
        script: "printf \"\$(date '+%F %T')\"",
        returnStdout: true
)

Kind regards,
Yves

--
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/0afaf8c1-57b9-a329-eac4-5f9510a77897%40wayland.
Reply | Threaded
Open this post in threaded view
|

Re: Scripts in environment stage

Ven H
Thanks a lot Yves. I also saw this in some samples. But, I have a Shared Library step, written to read a Yaml file from URL and return a Yaml Object. However, it is not returning the Yaml object when I call the step, although it is not throwing any error.

Regards,
Venkatesh


On Wed, Dec 9, 2020 at 1:07 AM Yves Schumann <[hidden email]> wrote:
Hi Ven

Am 08.12.2020 um 18:56 schrieb Ven H:
> Can we have script block or credential block to perform some logic
> inside the environment stage in Jenkinsfile?

I'm doing such things without issues. Some examples:

GIT_COMMIT_SHORT = sh(
        script: "printf \$(git rev-parse --short ${GIT_COMMIT})",
        returnStdout: true
)
CURRENT_DATE = sh(
        script: "printf \"\$(date '+%F %T')\"",
        returnStdout: true
)

Kind regards,
Yves

--
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/0afaf8c1-57b9-a329-eac4-5f9510a77897%40wayland.

--
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/CAPp28ereZ0RnVCv0eOABJDC-uySJJE1QJF96cVSo5qB8QnTLAg%40mail.gmail.com.