前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Groovy Jenkins Pipeline

Groovy Jenkins Pipeline

作者头像
DevOps云学堂
发布2019-11-12 20:39:45
1.3K0
发布2019-11-12 20:39:45
举报
文章被收录于专栏:DevOps持续集成DevOps持续集成

问题: 在许多微服务的场 景下,乏味且难以跟踪更改

Jenkins是一种广泛使用的CICD工具。多微服务的场景下流水线非常复杂。进行一些很小的变更都是一项繁琐的任务,例如更新一个URL一样。因为必须为每个微服务都进行更改。由于缺少更改日志,因此也很难跟踪进行了哪些更改以及由谁进行更改。

解决方案:使用“ Jenkins Pipeline”将作业定义为Groovy代码

使用插件套件“ Jenkins Pipeline”,您可以将不同的作业定义为Groovy代码。然后,您可以将其检入到首选的版本控制系统中,并维护和进一步开发项目代码。与多分支流水线连接时,将根据“ Jenkinsfile”中的说明自动构建项目的所有分支。

Groovy代码示例

一个具有多种服务的项目,全部使用Maven构建。分支开发中的合并是为了构建新版本。

代码语言:javascript
复制
Coffee-Service, Food-Service: Jenkinsfile
def pipeline
stage('Load pipeline') {
    //  Load the pipeline from the shared repository
    fileLoader.withGit(
    'https://url-to-pipeline-repo.git',
    'master',
    ' id-of-in-jenkins-stored-credentials') {
        //  Every service is able to use pipeline.groovy
        pipeline = fileLoader.load('pipeline.groovy')
    }
}
pipeline.execute()
Pipeline Repo: pipeline.groovy

def execute() {
    stage('Checkout') {
        checkout scm
    }
    stage('Build service') {
        sh "mvn clean install"
    }
    // The variable env.BRANCH_NAME is automatically set to the current branch.
    // As a consequence of this feature the pipeline can deal with every new branch
    if ("develop".equals(env.BRANCH_NAME) {
        stage('Release') {
            sh "mvn release:prepare release:perform"
        }
    }
}

文章来源

文章源地址:https://www.jambit.com/en/latest-info/toilet-papers/groovy-jenkins-pipeline-baby/

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2019-11-06,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 DevOps持续集成 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 问题: 在许多微服务的场 景下,乏味且难以跟踪更改
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档