Jenkins pipeline executes script files in the project directory

There is a script file in the root directory of the jenkins project, as shown in the figure
Please add a picture description

There is a simple output in the file
Please add a picture description

We want to execute this script file in the jenkins pipeline, how to configure the jenkins pipe command

First of all, to be clear, we are in the jenkins pipeline, the default is the root directory of the corresponding project folder in the Jenkins workspace folder, for example, the pipe project we are currently testing is named Pipeline in jenkins, then Our current path is under the file path as shown in the figure below
Please add a picture description

Therefore, we can get the script file (./) through ./liubo.sh to refer to the current path

Therefore, if we want to execute the liubo.sh script file, we can pass the command

pipeline {
    agent any
     environment {
        liubosh = "./liubo.sh"
    }
    stages {
        stage('checkout') {
            steps {
                  git branch: "master", url: "https://gitee.com/liuboliu/pengpailiubo.git"
            }
        }
         stage('build') {
            steps {
                 sh """
                   chmod -R +x ${liubosh}
                    ${liubosh}
                 """
            }
        }
    }
}

Execution, as shown in the figure below, successfully executes the scriptPlease add a picture description

Guess you like

Origin blog.csdn.net/LIUXIAOXIAOBO/article/details/131256705