首页 > 其他分享 >continuous deployment with Jenkins

continuous deployment with Jenkins

时间:2023-01-24 23:22:29浏览次数:38  
标签:tags continuous when sh tag steps deployment Jenkins stage

Deploying from a Git Tag -- buildingTag

https://notesfromthelifeboat.com/post/deploying-from-a-git-tag/

If you want to evaluate your changes in the staging environment automatically via a smoketest script, and push to production on a successful test, you don’t need a parameter at all; you can set the ENVIRONMENT for each stage in the pipeline:

pipeline {
    agent { label 'myLabel' }
    environment {
        GIT_TAG = sh(returnStdout: true, script: 'git describe --always').trim()
    }
    stages {
        stage("Checkout") {
            steps {
                checkout scm
            }
        }
        stage("Test") {
            steps {
                sh('make test')
        }
        }
    stage("Deploy to Staging") {
        when {
        buildingTag()
        }
        environment {
        ENVIRONMENT = 'staging'
        }
        steps {
        sh('make deploy')
        }
    }
    stage("Smoketest") {
        steps {
                sh('make smoketest')
        }
        }
    stage("Deploy to Production") {
        when {
            buildingTag()
            }
            environment {
            ENVIRONMENT = 'production'
            }
            steps {
            sh('make deploy')
            }
        }
    }
}

 

When using tags -- tag

https://www.jenkins.io/blog/2018/05/16/pipelines-with-git-tags/

One common pattern for automated releases I have seen and used relies on Git tags as the catalyst for a release process. The immutable nature of releases and the immutable nature of tags can definitely go hand in hand, but up until few months ago Jenkins Pipeline was not able to trigger effectively off of Git tags.

pipeline {
    agent any
    stages {
        stage('Build') {
            steps {
                sh 'make package'
            }
        }
        stage('Test') {
            steps {
                sh 'make check'
            }
        }
        stage('Deploy') {
            when { tag "release-*" }
            steps {
                echo 'Deploying only because this commit is tagged...'
                sh 'make deploy'
            }
        }
    }
}

 

when

https://www.cnblogs.com/rxysg/p/15682060.html

buildingTag :如果pipeline所执行的代码被打了tag,则执行

when {
    buildingTag()
}

tag:如果pipeline所执行的代码被打了tag,且tag名称符合规则,则执行。如果tag的参数为空,即tag ( ),则表示不论tag名称是什么都执行,与buildingTag的效果相同。

when {
    tag "release-*"
}

tag条件支持comparator参数,支持的值如下。
EQUALS:简单的文本比较

when {
    tag pattern "release-3.1", comparator: "EQUALS"
}

GLOB(默认值) :Ant风格路径表达式。由于是默认值,所以使用时一般省略。

when {
    tag pattern "release-*", comparator: "GLOB"
}

REGEXP∶正则表达式

when {
    tag pattern "release-\\d+", comparator: "REGEXP"
}

 

 

Configure the Jenkins project

https://comquent.de/de/de-triggering-jenkins-when-new-tags-are-created/

There are two changes that need to be applied in the Jenkins server. We should enable the Poll SCM build trigger in our pipeline job setting and enter a Schedule. This way, Jenkins will be able to check our project in Bitbucket for any changes. Then in the SCM section on the pipeline job configuration panel, we can enter the following settings:

  • Refspec: +refs/tags/*:refs/remotes/origin/tags/*
  • Branch: specifier **/tags/**

That’s all, the configuration is done and now it is time to check if this is working.

 

标签:tags,continuous,when,sh,tag,steps,deployment,Jenkins,stage
From: https://www.cnblogs.com/lightsong/p/17066524.html

相关文章

  • 公司内网jenkins编译拿不到nexus的依赖库
    公司内网jenkins编译拿不到nexus的依赖库话说我们公司内网有个docker部署的nexus,nexus是一个Maven仓库管理器。有时开发会自己上传项目依赖库(以前是我上传的,后来给回......
  • Windows10系统安装Jenkins
    注意的细节Jenkins下载选择Windows进入页面就会自动下载安装时需要测试端口是否可用选择jdk目录,要选择正确的目录只选到D:\software\jdk-11.0.17_windows-x64_bin会报错办公......
  • Jenkins集成SonarQube实现代码质量检查
    ​一、SonarQube简介   SonarQube是一个开源平台,用于管理源代码的质量。Sonar不只是一个质量数据报告工具,更是代码质量管理平台。支持Java、Python、C、C++、Go等多......
  • minikube上部署jenkins
    minikube上部署jenkins将jenkins部署到minikube上,并提供外网访问相关minikube安装和操作参考:https://blog.iwiki.ink/archives/ubuntu安装minikubekuberneteshttps:/......
  • 106 jenkins
    [root@jenkins~]#dockerpsCONTAINERIDIMAGECOMMANDCREATEDS......
  • Gitlab集成jenkins及docker自动化部署教程
    Gitlab集成jenkins及docker自动化部署教程能实现提交代码到gitlab后,我们只需要合并代码到指定分支就可以上Jenkins自动拉取最新代码并重新构建部署1、登录Jenkins点击如......
  • linux jenkins maven工程创建打jar包
    1.首相在Linux上安装Java环境(请自行百度)2.安装maven(简单说一下步骤,下载maventar包,解压后配置环境变量,mvn-v命令验证)配置maven依赖路径,打包时要用到依赖,编辑settings.xml......
  • linux jenkins添加windows节点
    1.添加jenkinsnode2.下载jar包上面提供两种方法,第一种下载文件,默认java去启动和运行程序。第二个,你可以拷贝这个命令,放到一个记事本文件,然后保存为bat文件,双击bat文件也......
  • Windows环境下实现Jenkins自动化部署
    1.Jenkins部署环境a.下载安装包​​​http://ftp-chi.osuosl.org/pub/jenkins/war-stable/​​​找最新的安装包进行下载(下载时间有点长)b.在安装包根路径下,运行命令jav......
  • Linux Jenkins安装配置Git
    1.卸载自带的gitapt-getremovegit2.验证是否卸载git--version3.下载git并将git添加到环境变量中wgethttps://github.com/git/git/archive/v2.2.1.tar.gz或者直接在......