Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use source command within Jenkins pipeline script

Tags:

I recently rewrite bash execution command into Jenkins pipeline. The old code is like

... source environment.sh //Build //Test ... 

Now I use pipeline script to wrap the command, like this

sh '''     ...     source environment.sh     //Build     //Test     ... ''' 

However, I got an error, as.../.jenkins/script.sh: line 9: source: environment.sh: file not found. When I try to less environment.sh, it display correctly. So I suspect something wrong with source command within sh wrap.

Before using pipeline, source environment.sh command is working fine in shell execution. So source is install at Jenkins server, it seems pipeline script don't know what is the source command.

How could I do to run source command within sh wrapped block?

like image 899
Neil Avatar asked Jul 29 '16 17:07

Neil


2 Answers

Replace source environment.sh with

. ./environment.sh 

Please note there is a space after first dot.

like image 102
Steephen Avatar answered Sep 21 '22 19:09

Steephen


source is a bash/ksh/etc extension, provided as a more "substantial" synonym for ..

In sh, you need to use . in case the underlying shell is one (such as dash) that does not support the command source.

sh '''     ...     . ./environment.sh     //Build     //Test     ... ''' 
like image 29
chepner Avatar answered Sep 23 '22 19:09

chepner