AVarf
AVarf

Reputation: 5199

How to source multiple scripts in different locations in jenkins

I need to source 2 scripts in different locations and then run docker-compose but I am facing error that the scripts must be sourced first.

I found this How to use source command within Jenkins pipeline script question and wrote my jenkins commnad as below:

. ../env/scriptA.sh arg-1 ../env/scriptB.sh ../compose/build.yml arg-2

But still facing that error. So how I can source all these scripts and build file in the jenkins?

Upvotes: 0

Views: 269

Answers (2)

AVarf
AVarf

Reputation: 5199

As Nahuel Fouilleul mentioned in his answer this is just one line and the script and yml files are other arguments and as I mentioned in the comment to Nahuel Fouilleul the problem is because of "[[" I can't source that script in shell environment of jenkins (even if the script has its own shebang) so I added the shebang to the shell block in jenkins as below and now it works.

sh '''#!/bin/bash -xe
. ../env/scriptA.sh arg-1 ../env/scriptB.sh ../compose/build.yml arg-2
echo "other commands"
'''

Upvotes: 0

Nahuel Fouilleul
Nahuel Fouilleul

Reputation: 19335

from bash manual

. (a period)

. filename [arguments]

Read and execute commands ...

the syntax is one filename and then positional parameters, it can't accept multiple files. Concatenating files doesn't allow to change paramters between calls, maybe a command sequence could be used if allowed

{ . file1 args ; . file2 args;}

Note the space after the first opening brace and semicolon before closing brace are important.

Upvotes: 1

Related Questions