简体   繁体   中英

Bash script never receives arguments when called from Jenkins pipeline

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?

put #!/bin/bash into the first line

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

otherwise . (dot) command could have different meaning

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM