【问题标题】:shell script returning not found on jenkins master using pipeline as code使用管道作为代码在jenkins master上找不到返回的shell脚本
【发布时间】:2020-01-21 14:00:37
【问题描述】:

我是 jenkins 的新手,正在尝试编写管道。运行作业时一切正常,但面临管道问题。从 github 签出后应该运行的脚本返回找不到文件。任何人都可以帮忙吗?附件是日志的图像。 https://i.stack.imgur.com/LuxGn.png 下面是我尝试执行的代码示例。

 stage('puppet master config checkout') {
        steps {
            echo "cloning github"
            git "https://github.com/rk280392/pipeline_scripts.git"
        }

    }
     stage('puppet master config build') { 
        steps {
            echo "running puppet master script"
            sh "puppet_master.sh"
        }

    }

【问题讨论】:

  • 你的 git-repo 的文件夹结构是什么?您正在调用脚本,但在 Jenkins 中缺少正确的文件夹结构。
  • 可以看到文件夹下的文件夹和脚本:-root@vagrant:/var/lib/jenkins/workspace# ls pipeline_script pipeline_script@2 pipeline_script@2@tmp pipeline_script@tmp
  • 已解决。需要使用./puppet_master.sh

标签: shell jenkins jenkins-pipeline pipeline


【解决方案1】:
  1. 在 git 步骤之后使用命令 sh 'ls' 检查文件脚本是否在此处。 一般来说,我建议不要使用 git step 而是使用 checkout,它更强大,更可靠
    checkout([
         $class: 'GitSCM',
         branches: scm.branches,
         extensions: scm.extensions,
         userRemoteConfigs: [[
             url: 'https://github.com/rk280392/pipeline_scripts.git'
         ]]
    ])
  1. 您的脚本可执行吗?您可以在使用点斜杠作为前缀 ./puppet_master.sh 运行它之前使用 chmod +x puppet_master.sh
sh 'sh puppet_master.sh'

【讨论】:

    猜你喜欢
    • 2021-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多