【发布时间】:2022-10-25 19:32:11
【问题描述】:
我想自定义 Jenkins 流水线阶段。
在下面的屏幕截图中,我不希望步骤 Approve K8s Dev Deployment 和 Create and Deploy to k8s Dev Environment 显示在管道阶段视图中,因为我正在根据我的分支名称跳过这些步骤。下面是当前的输出。
我希望在没有Approve K8s Dev Deployment 和Create and Deploy to k8s Dev Environment 的情况下看到如下所示的管道阶段视图。我想要我的预期输出如下。我错过了任何插件吗?我怎样才能做到这一点?
下面是我的常规代码:
stages{
stage('Checkout') {
steps{
checkout scm
}
}
// Maven Build and Unit Tests Dev
stage('Build and Unit Tests') {
steps{
build(configuration)
}
}
// SonarQube Analysis
stage('SonarQube analysis') {
steps{
sonarQubeGating(configuration)
}
}
// Build Docker Image and Push to Artifactory
stage('Build Docker Image and Push to Artifactory') {
steps{
artifactoryImagePush(configuration)
}
}
// Approve DEV Deployment
stage('Approve K8s Dev Deployment') {
when {
anyOf {
expression {
return (env.GIT_BRANCH.startsWith('master') || env.GIT_BRANCH.startsWith('hotfix-'))
}
}
}
steps {
approveDeployment()
}
}
// Create and Deploy to Dev Environment
stage('Create and Deploy to k8s Dev Environment') {
when {
anyOf {
expression {
return (env.GIT_BRANCH.startsWith('master') || env.GIT_BRANCH.startsWith('hotfix-'))
}
}
}
steps {
withCredentials([string(credentialsId: "$env.K8S_DEV_NS_TOKEN", variable: 'DEV_TOKEN')]) {
kubernetesDeploy(hcEnv: 'dev', hcToken: "${DEV_TOKEN}")
}
}
}
}
【问题讨论】:
标签: jenkins jenkins-pipeline jenkins-groovy