Environment variable - shell

15 views
Skip to first unread message

Elango Thiagarajan

unread,
Feb 2, 2021, 10:58:14 AM2/2/21
to Jenkins Users
Hi folks,

I am very new to Jenkins. Kindly help me through.

I have few parameters declared in my pipeline script and i need to pass that to environment  variables. 

i tried like below

sh """
     export GOOL=${params.GOOL}

but while execution is throwing bad substitution exception. Any pointers on what wrong here


The exported enviornmnet variable will be used as input to run a docker image.

Ing. Jheison Rodriguez

unread,
Feb 2, 2021, 11:13:18 AM2/2/21
to jenkins...@googlegroups.com

Correct if I’m wrong guys, but I think you should skip the $ for \$

 

 

 

Jheison Rodriguez

--
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/82ce9f00-434d-4a99-8e70-0233fecde1f6n%40googlegroups.com.

 

gma...@gmail.com

unread,
Feb 2, 2021, 11:17:50 AM2/2/21
to jenkins...@googlegroups.com

Hi,

Jenkins does it for you if you use the “environment” block.

 

https://www.jenkins.io/doc/book/pipeline/syntax/#environment

 

There is an example that uses “sh” command to show how Jenkins automatically inject environment variable inside a shell.

 

Cheers,

Gianluca.

 

 

From: jenkins...@googlegroups.com <jenkins...@googlegroups.com> On Behalf Of Elango Thiagarajan
Sent: 02 February 2021 15:23
To: Jenkins Users <jenkins...@googlegroups.com>
Subject: Environment variable - shell

 

Hi folks,

--

Jérôme Godbout

unread,
Feb 2, 2021, 11:54:04 AM2/2/21
to jenkins...@googlegroups.com

Can you use

withEnv([“GOOL =${params.GOOL”}]) {

   sh(…);

}

 

Jérôme Godbout
Software / Firmware Lead

C: (581) 777-0050 
O: (418) 800-1073 ext.: 109  
godb...@amotus.ca

dimonoff.com   |    amotus.ca

 

From: jenkins...@googlegroups.com <jenkins...@googlegroups.com> On Behalf Of Elango Thiagarajan
Sent: February 2, 2021 10:23 AM
To: Jenkins Users <jenkins...@googlegroups.com>
Subject: Environment variable - shell

 

Hi folks,

--

Elango Thiagarajan

unread,
Feb 4, 2021, 8:14:48 AM2/4/21
to Jenkins Users
Thanks  Jerome. It worked perfectly.
Reply all
Reply to author
Forward
0 new messages