Jenkins Job DSL-管道阶段



我正在编写一个groovy脚本,其中包含部署terraform的作业。我正在使用Job DSL,并且JCasC正在实现种子作业,一切都很好。然后我有一个repo,其中包含groovy文件,包含作业。

如果我把groovy文件作为一个单独的作业来保持简单,那么它可以很好地工作。

然而,我希望能够构建一个具有构建阶段的管道。我知道我可以在Jenkinsfile&然后从Job DSL调用那个jenkins文件。。但理想情况下,为了简单起见,我希望将整个管道保留在groovy文件中。

我有这个作为入门:

pipelineJob('Deploy-K8s-Cluster') {
definition {
cps {
script('''
pipeline {
agent any
stages {
stage('Checkout'){
steps {
scm {
git {
branch('master')
remote {
url 'jenkins@bitbucket.org:jjbbtt/aws-infrastructure.git'
credentials('bitbucket-ssh')
}
}
}
}
}
stage('Terraform Initialize') {
steps {
'terraform init'
}
}
stage('Terraform Plan') {
steps{
'terraform plan -out=create.tfplan'
}
}
stage('Terraform Apply') {
steps{
'terraform apply -auto-approve create.tfplan'
}
}
stage('Deploy Sealed Secrets Controller') {
steps{
'kubectl apply -f sealed-secrets/controller.yaml'
}
}
}
}
'''.stripIndent())
sandbox()
}
}
}

然而,我看到了这个错误:

General error during semantic analysis: There's no @DataBoundConstructor on any constructor of class javaposse.jobdsl.plugin.casc.FromUrlScriptSource

我尝试了各种方法,读了很多文档。。但问题是我对Job DSL不是很熟悉。

我是不是错过了一些简单的东西?还是完全找错树了?

我想明白了。。我的误解是没有看到cps的script()部分中的任何内容都不是Job DSL。如果我更改语法,它会起作用。

最新更新