jenkins - 将 jenkinsfile 转换为 gitlabci.yaml
问题描述
我有一个复杂的 jenkinsfile groovy 脚本,我想将其转换为 gitlabCI yaml 脚本。
pipeline {
agent {
docker {
image "my_repo:master"
registryUrl "my_ECR_Img"
registryCredentialsId "my_registry_CredentialsId"
label "jenkins-infrastructure"
alwaysPull true
}
}
parameters {
gitParameter name: 'COMMIT_HASH',
type: 'PT_REVISION',
defaultValue: 'master',
branch: 'origin/master',
useRepository: ".*infra.git"
choice(name: 'TARGET_STAGE', choices: ['dev', 'staging', 'prod', 'test'], description: 'Target stage for commit deployment')
booleanParam(name: 'SKIP_PLAN', defaultValue: "false", description: 'Skip validate/plan step (e.g. when retrying a failed pipeline)')
choice(name: 'MODULE', choices: ['all','module1','module2','module3'], description: 'which module to apply - select all for all modules')
}
environment {
AWS_REGION = 'eu-central-1'
COMMIT_HASH = sh(
script: "printf \$(git describe --always)",
returnStdout: true
)
PROJECT = "eve"
REPOSITORY_NAME = "infra"
AUTOMATED_BUILD = "${params.COMMIT_HASH == "master" ? "TRUE" : "FALSE"}"
AWS_ENVIRONMENT = "${params.COMMIT_HASH == "master" ? "dev" : "${params.TARGET_STAGE}"}"
MODULE = "${params.COMMIT_HASH == "master" ? "all" : "${params.MODULE}"}"
}
stages {
stage('automated pipeline') {
when {
allOf {
anyOf {
changeRequest()
branch 'master'
}
environment name: 'AUTOMATED_BUILD', value: 'TRUE'
}
}
stages {
stage('pull request builds') {
when {
changeRequest()
}
steps {
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', credentialsId: 'JENKINS_AWS'],
sshUserPrivateKey(credentialsId: 'JENKINS-SSH', keyFileVariable: 'SSH_KEY')]) {
script {
terraformPlan(environment: 'dev', lock: false, tfsec: true)
}
}
}
post {
always {
junit allowEmptyResults: true, testResults: "**/*/junit.xml"
}
success {
echo "Terraform TFSec Passed"
}
failure {
echo "Terraform TFSec Failed"
}
}
}
下面还有一些其他代码,但我只想翻译这个块!我浏览了 gitlabCI 文档,但问题是,这不仅仅是关于翻译,而是在将管道从 jenkins 迁移到 gitlab 时使用不同的方法。任何帮助将不胜感激。
解决方案
推荐阅读
- android - 如何在kotlin android中使用viewmodel和数据绑定基于所有editetext启用/禁用按钮不为空
- python - 我需要找到自然数的排列,使得 abs(pos[i]-i==k) 其中 k 对于所有自然数都是常数
- swift - 带有 Codable 的可失败初始化器
- android - Listview 到 Recycler 视图的转换
- flutter - 如何在颤动中显示更多数字选择器列表的元素?
- javascript - 如何在Javascript中在JSON周围添加[]打开和关闭方括号?
- firebase - 用带参数的符号更新对象?
- excel - 宏中的 Sumproduct
- node.js - 如何克服 mongodb 的大小限制以及一般存储、发送和检索大型文档?
- java - 我想将所有联系人保存并检索到 Firebase Firestore,需要结构来保存和检索联系人