没有这样的DSL方法`stages` [英] no such DSL method `stages`

查看:29
本文介绍了没有这样的DSL方法`stages`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为 Jenkins 创建我的第一个 Groovy 脚本:

I'm trying to create my first Groovy script for Jenkins:

查看这里后https://jenkins.io/doc/book/pipeline/,我创建了这个:

After looking here https://jenkins.io/doc/book/pipeline/, I created this:

node {
  stages {

    stage('HelloWorld') {
      echo 'Hello World'
    }

    stage('git clone') {
      git clone "ssh://git@mywebsite.com/myrepo.git"
    }

  }
}

但是,我得到:

java.lang.NoSuchMethodError: 在步骤中找不到这样的 DSL 方法阶段"

我错过了什么?

此外,如何在不以纯文本格式写入密码的情况下将我的凭据传递给 Git 存储库?

Also, how can I pass my credentials to the Git Repository without writing the password in plain text?

推荐答案

你混淆并混合了 Scripted PipelineDeclarative Pipeline,为了完全不同 见这里.但短篇故事:

You are confusing and mixing Scripted Pipeline with Declarative Pipeline, for complete difference see here. But the short story:

  • declarative pipelines 是管道 DSL 的新扩展(它基本上是一个只有一步的管道脚本,一个带有参数的管道步骤(称为指令),这些指令应该遵循特定的语法.这种新格式的重点在于它更加严格,因此对于管道的新手来说应该更容易,允许图形编辑等等.
  • 脚本化管道是高级需求的后备.
  • declarative pipelines is a new extension of the pipeline DSL (it is basically a pipeline script with only one step, a pipeline step with arguments (called directives), these directives should follow a specific syntax. The point of this new format is that it is more strict and therefor should be easier for those new to pipelines, allow for graphical editing and much more.
  • scripted pipelines is the fallback for advanced requirements.

因此,如果我们查看您的脚本,您首先会打开一个 node 步骤,该步骤来自脚本化管道.然后使用 stages,它是 declarative pipeline 中定义的 pipeline 步骤的指令之一.所以你可以例如写:

So, if we look at your script, you first open a node step, which is from scripted pipelines. Then you use stages which is one of the directives of the pipeline step defined in declarative pipeline. So you can for example write:

pipeline {
  ...
  stages {
    stage('HelloWorld') {
      steps {
        echo 'Hello World'
      }
    }
    stage('git clone') {
      steps {
        git clone "ssh://git@mywebsite.com/myrepo.git"
      }
    }
  }
}

所以如果你想使用声明式管道,那就是要走的路.

So if you want to use declarative pipeline that is the way to go.

如果你想脚本化管道,那么你写:

node {
  stage('HelloWorld') {
    echo 'Hello World'
  }

  stage('git clone') {
    git clone "ssh://git@mywebsite.com/myrepo.git"
  }
}

例如:跳过阶段块.

这篇关于没有这样的DSL方法`stages`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆