从 Jenkins 管道执行 shell 脚本

Execute shell script from Jenkins Pipeline

我正在尝试从我的 jenkins 管道执行 shell 脚本。我在 shell 命令中提供了绝对路径和相对路径,但在构建管道时仍然遇到 No such file or directory 错误。

这是一个简单的脚本,但还不能正常工作。

尝试 1:

         stage ( 'Executing shell script' ) {
             steps {
                     sh '/home/patching/shell_script.sh'
                     
                     }
                   }                 

尝试 2:

         stage ( 'Executing shell script' ) {
             steps {
                     sh './shell_script.sh'
                     
                     }
                   }                 

尝试 3:

         stage ( 'Executing shell script' ) {
             steps {
                     dir ('/home/patching/shell_script.sh){
                         sh './shell_script.sh'
                   }
                }

我真的不知道脚本到底出了什么问题。有人可以帮我解决这个问题吗?

我遇到了无法找到我想要的文件的问题 运行。 运行宁在不同的奴隶。

你能试试这个吗

pipeline {
agent any
stages {
    stage('Hello World') {
        steps {
            script {
               sh '''
               
                /home/ubuntu/First.sh
               
               
               '''
                
            }
        }
    }
  }
}