Home > database >  Bash script never receives arguments when called from Jenkins pipeline
Bash script never receives arguments when called from Jenkins pipeline

Time:06-15

I'm running a declarative Jenkins pipeline on Ubuntu 18.04 slave. My issue is that whenever I'm trying to provide arguments from a sh step to a bash script, the arguments are not there. When running the exact same commands from either a terminal directly or another script file (similarly how Jenkins does it via temp file) the arguments work fine.

The Jenkinsfile looks something like

pipeline {
    agent { label "ubuntu" }
    options { timeout(time: 1, unit: 'HOURS') }
    stages {
        stage('Build') {
            steps {
                sh """
                #!/bin/bash
                ...
                . ./Scripts/install_tools.sh "force"
                """
            }
        }
    }
}

The pipeline itself runs smooth and does what I need it to do. The problem is that when calling install_tools.sh no arguments are found. The script looks something like

#!/bin/bash
echo "Running $0"
echo "Args: $@"

...

The line echo "Args: $@" I have tried also with $* and $1 - Each time the arguments are returned as empty, but only when running from the pipeline. It seems to me that this is related to some Groovy stuff, but I have no clue what.

How do I call a bash script during the pipeline and get the arguments passed properly?

CodePudding user response:

put #!/bin/bash into the first line

sh """#!/bin/bash
   . ./Scripts/install_tools.sh "force"
   """

otherwise . (dot) command could have different meaning

  • Related