Scripts in environment stage

12 views
Skip to first unread message

Ven H

unread,
Dec 8, 2020, 12:57:45 PM12/8/20
to jenkins...@googlegroups.com
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

Yves Schumann

unread,
Dec 8, 2020, 2:37:18 PM12/8/20
to jenkins...@googlegroups.com
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

Ven H

unread,
Dec 9, 2020, 12:45:15 AM12/9/20
to jenkins...@googlegroups.com
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


--
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/0afaf8c1-57b9-a329-eac4-5f9510a77897%40wayland.
Reply all
Reply to author
Forward
0 new messages