Jenkins linter:不包含“管道”步骤

问题描述 投票:0回答:1

在检查工作 Jenkins 脚本时,我得到以下反馈:

Jenkinsfile content 'node('xxx') ... did not contain the 'pipeline' step.

给出相同错误的简短示例:

node('xxx'){
  try  {
    stage("Get jenkins utils")    {
      echo 'get utils to support my builds'
    }
  }
  catch (Exception err)  {
    echo err.getMessage()
  }
}

如何添加管道步骤来解决此反馈而不影响管道脚本的当前工作。理想情况下,我希望 Jenkins 将其作为脚本化管道进行检查。

我不确定管道步骤的目的是什么以及在哪里添加它。感觉try catch必须换成不同的机制了

jenkins jenkins-plugins
1个回答
0
投票

查看 Jenkins 管道语法文档,其说明非常简单:

所有有效的声明性管道必须包含在管道块中,例如:

pipeline {
    /* insert Declarative Pipeline here */
}

所以对于初学者你可以尝试:

pipeline {
  node('xxx'){
  try  {
    stage("Get jenkins utils")    {
      echo 'get utils to support my builds'
    }
  }
  catch (Exception err)  {
    echo err.getMessage()
  }
}

如果您想进一步提高 Jenkins 管道技能,CloudBees(一家由 Jenkins 创建者创建、提供 Jenkins 支持的公司)在其 GitHub 中提供了 一个很好的教程

© www.soinside.com 2019 - 2024. All rights reserved.