我正在编写一个 groovy 脚本,用于部署 terraform。我正在使用 Job DSL 并让 JCasC 实现种子作业,一切正常。然后我有一个包含作业的 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 不是很熟悉。
我错过了一些简单的东西吗?还是完全找错了树?
答案 0 :(得分:0)
我想通了。我的误解是没有看到 cps 的 script()
部分中的任何内容都不是 Job DSL。如果我更改语法,就可以工作。