How to use source command in jenkins pipeline script

I recently rewrote the bash run command in the Jenkins pipeline. Old code is like

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

Now I use a script pipeline to wrap a command like this

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

However, I got an error like .../.jenkins/script.sh: line 9: source: environment.sh: file not found . When I try less environment.sh , it displays correctly. Therefore, I suspect something is wrong with the source command inside sh wrap .

Before using the pipeline, the source environment.sh command works fine when executing a shell. So the source is installed on the Jenkins server, it seems that the script pipeline does not know what the original command is.

How can I do to run the source command in sh shackped block?

+7
linux bash shell jenkins jenkins-pipeline
source share
2 answers

Replace source environment.sh with

 . ./environment.sh 

Note that there is a space after the first dot.

+7
source share

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

In sh you need to use . if the base shell is one (for example, dash ) that does not support the source command.

 sh ''' ... . environment.sh //Build //Test ... ''' 
+2
source share

All Articles