【问题标题】:sshCommand not found in Jenkins with "ssh pipeline steps" installed在安装了“ssh 管道步骤”的 Jenkins 中找不到 sshCommand
【发布时间】:2021-04-08 19:09:52
【问题描述】:

我尝试在我的 Jenkinsfile 上使用 sshCommand 并且已经安装了“SSH Pipeline Steps”插件, 但 Jenkins 构建错误:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 60: Unknown stage section "sshCommand". Starting with version 0.5, steps in a stage must be in a ‘steps’ block. @ line 60, column 5.
       stage('Remote SSH') {
       ^

WorkflowScript: 60: Multiple occurrences of the sshCommand section @ line 60, column 5.
       stage('Remote SSH') {
       ^

WorkflowScript: 60: Unknown stage section "sshCommand". Starting with version 0.5, steps in a stage must be in a ‘steps’ block. @ line 60, column 5.
       stage('Remote SSH') {
       ^

WorkflowScript: 60: Expected one of "steps", "stages", or "parallel" for stage "Remote SSH" @ line 60, column 5.
       stage('Remote SSH') {
       ^

4 errors

这是我的詹金斯文件:

def remote = [name: "${host}", host: "${host}", user: "root", allowAnyHosts: true]
stage('Remote SSH') {
      sshCommand remote: remote, command: "npm install"
      sshCommand remote: remote, command: "npm run start"
}

这里已经安装好了:

【问题讨论】:

    标签: jenkins ssh jenkins-pipeline jenkins-declarative-pipeline


    【解决方案1】:

    如果你想通过 Jenkins Pipeline 使用插件的接口,那么插件公开的函数或方法必须都包含在 steps 块中:

    stage('Remote SSH') {
      steps {
        sshCommand remote: remote, command: "npm install"
        sshCommand remote: remote, command: "npm run start"
      }
    }
    

    您显示的错误将得到修复。

    【讨论】:

    • 谢谢,是的,在我使用舞台内的步骤后它可以工作
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-30
    • 2017-11-14
    • 1970-01-01
    • 2020-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多