Run bash command on jenkins pipe

I want to run the bash command in the jenkins pipeline instead of the shell command inside the groovy script:

I already tried using "#! / Bin / bash":

stage('Setting the variables values') { steps { sh ''' #!/bin/bash echo "hello world" ''' } } 

And also tried using 'bash' instead of 'sh'

 stage('Setting the variables values') { steps { bash ''' #!/bin/bash echo "hello world" ''' } } 

Obviously, my team is more complicated than the "echo salutation world."

+7
linux bash shell jenkins groovy
source share
3 answers

The Groovy script you provided formats the first line as an empty line in the resulting script. Shebang telling the script to run with / bin / bash instead of / bin / sh should be on the first line of the file or ignored.

So you should format Groovy as follows:

 stage('Setting the variables values') { steps { bash '''#!/bin/bash echo "hello world" ''' } } 

And it will run with / bin / bash.

+7
source share

According to this document , you should do it as follows:

 node { sh "#!/bin/bash \n" + "echo \"Hello from \$SHELL\"" } 
+3
source share

try the bit "" line ex: bat 'del C: \ Hello.txt'

-3
source share

All Articles