[官网] : https://jenkins.io/zh/[文档] : https://jenkins.io/zh/doc/[下载] : https://jenkins.io/zh/download/ # war -> http://mirrors.jenkins.io/war-stable/latest/jenkins.war[run]#!/usr/bin/env bashnohup java -jar jenkins.war --ajp13Port=-1 --httpPort=8999 > log.file 2>&1 &
[Jenkins Pipeline] # 一套插件, 将持续交付的实现和实施集成到 Jenkins 中 // Jenkins Pipeline 的定义通常被写入到一个文本文件(称为 Jenkinsfile)中 # 步骤 step[Jenkinsfile] : https://jenkins.io/doc/book/pipeline/jenkinsfile///Jenkinsfile (Declarative Pipeline)pipeline { agent any stages { stage('Build') { steps { sh 'echo "Hello World"' sh ''' echo "Multiline shell steps works too" ls -lah ''' } } }}//retry(3) { sh './flakey-deploy.sh'}timeout(time: 3, unit: 'MINUTES') { sh './health-check.sh'}//timeout(time: 3, unit: 'MINUTES') { retry(5) { sh './flakey-deploy.sh' }}// 完成post { always { echo 'This will always run' } success { echo 'This will run only if successful' } failure { echo 'This will run only if failed' } unstable { echo 'This will run only if the run was marked as unstable' } changed { echo 'This will run only if the state of the Pipeline has changed' echo 'For example, if the Pipeline was previously failing but is now successful' } }
[agent] # 定义执行环境 : Jenkins在哪里以及如何执行Pipeline或者Pipeline子集 // 所有在块block中的步骤steps会被Jenkins保存在一个执行队列中。 一旦一个执行器 executor 是可以利用的,这些步骤将会开始执行。 // 一个工作空间 workspace 将会被分配, 工作空间中会包含来自远程仓库的文件和一些用于Pipeline的工作文件 // https://jenkins.io/doc/book/pipeline/syntax#agent[environment 环境变量] # 环境变量 (全局或阶段 (stage))//Jenkinsfile (Declarative Pipeline)pipeline { agent any environment { DISABLE_AUTH = 'true' DB_ENGINE = 'sqlite' } stages { stage('Build') { steps { sh 'printenv' } } }}[清理通知]Jenkinsfile (Declarative Pipeline)pipeline { agent any stages { stage('No-op') { steps { sh 'ls' } } } post { always { echo 'One way or another, I have finished' deleteDir() /* clean up our workspace */ } success { echo 'I succeeeded!' } unstable { echo 'I am unstable :/' } failure { echo 'I failed :(' } changed { echo 'Things were different before...' } }}// 电子邮件post { failure { mail to: 'team@example.com', subject: "Failed Pipeline: ${currentBuild.fullDisplayName}", body: "Something is wrong with ${env.BUILD_URL}" }}// Hipchatpost { failure { hipchatSend message: "Attention @here ${env.JOB_NAME} #${env.BUILD_NUMBER} has failed.", color: 'RED' }}// Slackpost { success { slackSend channel: '#ops-room', color: 'good', message: "The pipeline ${currentBuild.fullDisplayName} completed successfully." }}[部署]Jenkinsfile (Declarative Pipeline)pipeline { agent any stages { stage('Build') { steps { echo 'Building' } } stage('Test') { steps { echo 'Testing' } } stage('Deploy') { steps { echo 'Deploying' } } }}