Jenkins 提供了 Open Blue Ocean 持续交付的流水线能力,是传统构建样式的升级版。

Open-Blue-Ocean-01

https://jenkins.io/doc/book/blueocean/pipeline-run-details/

一个真实的Pipeline


pipeline

学习其它厂商的最佳实践,并逐步实现自己的Pipeline最佳实践。

Jenkins Pipeline Best Practices
CloudBees Top 10 Best Practices

图为cloudbees流水线

Open-Blue-Ocean-03

有不少插件可供选择

Open-Blue-Ocean-04

Jenkins pipeline 创建管理我们由Open Blue Ocean来完成,此外还有classic UI 和在 SCM手动创建Jenkinsfile。

这里可以对Pipeline Syntax(Pipeline domain-specific language (DSL) syntax)做一定了解。

得益于Jenkins内嵌的Groovy支持,加上丰富的Step库,通过编写自定义Pipeline脚本你几乎可以实现任何复杂的构建、发布流程。

https://jenkins.io/doc/pipeline/steps/

一些配置信息(仅供参考):

http://192.168.0.249:26451/service/dev/jenkins-prod/job/dev-huihoo-edu/configure

git仓库:[email protected]:server/huihoo-edu.git
构建环境:Mesos Single-Use Slave
Gradle版本:Gradle 3.3
仓库名和标签:huihoo/huihoo-edu 1.0.0
Docker registry URL:http://master.mesos:5000
Marathon URL:http://leader.mesos/service/marathon-user

Docker image for Pipeline demo

docker volume create --name=m2repo
sudo chmod a+rw $(docker volume inspect -f '{{.Mountpoint}}' m2repo)
docker run --rm -p 127.0.0.1:2222:2222 -p 127.0.0.1:8080:8080 -p 127.0.0.1:8081:8081 -p 127.0.0.1:9418:9418 -ti -v m2repo:/m2repo jenkinsci/workflow-demo

Open-Blue-Ocean-05

Open-Blue-Ocean-06

Open-Blue-Ocean-07

Open-Blue-Ocean-08

一个简单的Pipeline,仅供参考

pipeline {
    agent none
    stages {
        stage('Example Build') {
            agent { docker 'maven:3-alpine' }
            steps {
                echo 'Hello, Maven'
                sh 'mvn --version'
            }
        }
        stage('Example Test') {
            agent { docker 'openjdk:8-jre' }
            steps {
                echo 'Hello, Java'
                sh 'java -version'
            }
        }
    }
}

得益于Jenkins内嵌的Groovy支持,加上丰富的step库,通过编写自定义Pipeline脚本你几乎可以实现任何复杂的构建、发布流程。也可将共享的Groovy脚本封装到一个自定义Jenkins Plugin中,然后安装到需要的Jenkins实例中,以后也可以进行统一升级,有效降低了维护成本。

通过Groovy编写Pipeline。

node {
stage 'Stage 1'
echo 'Hello World 1'
stage 'Stage 2'
echo 'Hello World 2'
stage 'Stage 3'
echo 'Hello World 3'
stage 'Stage 4'
echo 'Hello World 4'
}

Open-Blue-Ocean-09

大家可试着对某个Git仓库拉代码、编译、打包、部署

流水线语法:http://192.168.0.249:10082/service/dev/jenkins-prod/job/huihoo-edu-pipeline/pipeline-syntax

可由Snippet Generator和Declarative Directive Generator生成流水线脚本。

需要 Docker Pipeline 插件

流水线需要的环境

Requirements To Use Durability Settings

  • Jenkins LTS 2.73+ or higher (or a weekly 2.62+)
  • For all the Pipeline plugins below, at least the specified minimum version must be installed
    • Pipeline: API (workflow-api) v2.25
    • Pipeline: Groovy (workflow-cps) v2.43
    • Pipeline: Job (workflow-job) v2.17
    • Pipeline: Supporting APIs (workflow-support) v2.17
    • Pipeline: Multibranch (workflow-multibranch) v2.17 – optional, only needed to enable this setting for multibranch pipelines.
  • Restart the master to use the updated plugins – note: you need all of them to take advantage

Open-Blue-Ocean-10

有很多 Jenkins Pipeline step 类型可供选择。

Shell Script
Print Message
Enforce time limit
Retry the body up to N times
Sleep
Windows Batch Script
Archive the artifacts
Allocate node
Accept GitLab Merge Request
Add comment on GitLab Merge Request
Allocate a docker node
Allocate workspace
Archive JUnit-formatted test results
Artifact Resolver
Bind credentials to variables
Build a job
Catch error and set build result
Change current directory
Checks if running on a Unix-like node
Cloud template provisioning
Color ANSI Console Output
Copy artifacts from another project
Determine current directory
Docker Node (⚠️ Experimental)
Error signal
Evaluate a Groovy source file into the Pipeline script
Expand a string containing macros
General Build Step
General Build Wrapper
General SCM
Git
Invoke Nexus Policy Evaluation
JIRA: Add a comment to issue(s)
JIRA: Issue selector
JIRA: Search issues
Load a resource file from a shared library
Load a shared library on the fly
Mail
Marathon Deployment
Nexus Artifact Uploader
Nexus Repository Manager Publisher
Notify gitlab about pending builds
PowerShell Script
Process Job DSLs
Provide Maven environment
Publish artifacts to S3 Bucket
Publish Cobertura Coverage Report
Publish HTML reports
Read file from workspace
Read trusted file from SCM
Record fingerprints of files to track usage
Recursively delete the current directory from the workspace
Resolves an SCM from an SCM Source and a list of candidate target branch names
Restore files previously stashed
Run arbitrary Pipeline script
S3 Copy Artifact
Set environment variables
SSH Agent
Stash some files to be used later in the build
Subversion
The milestone step forces all builds to go through in order
Timestamps
Update the commit status in GitLab
Update the commit status in GitLab depending on the build status
Use a tool from a predefined Tool Installation
Validate a file containing a Declarative Pipeline
Verify if file exists in workspace
Wait for condition
Wait for interactive input
Write file to workspace



2 对 “Open Blue Ocean”的想法;

发表评论

OpenID

电子邮件地址不会被公开。 必填项已用*标注

Anonymous

电子邮件地址不会被公开。 必填项已用*标注