1. 創(chuàng)建一個沒有任何state的pipeline
2. 開始創(chuàng)建Groove腳本去構(gòu)建一個Job
2.1 借助腳本生成器生成腳本的方法(知識類忌卤,可以忽略掉)
2.1.1 構(gòu)建
2.1.2 發(fā)布測試報告
2.1.3 打包構(gòu)建的制品
2.1.4 選擇一個node運行構(gòu)建
2.1.5 一個構(gòu)建job的特定步驟
2.2 創(chuàng)建一個pipeline
2.2.1 方法一: 把腳本直接寫在Jenkins里面(可以改良)
//注意在windows環(huán)境下使用bat研侣,unix下使用sh命令去執(zhí)行命令
pipeline {
agent any
stages {
stage('Checkout') {
steps {
echo 'Checkout...'
git url: 'git@github.com:yinbodotcc/simpleTestCanDeleteLater.git'
//checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'git@github.com:yinbodotcc/simpleTestCanDeleteLater.git']]])
echo 'Checkout finished'
}
}
stage('Compile...') {
steps {
//build 'petclinic'
//unix環(huán)境使用sh代替bat
//sh 'mvn clean compile'
bat 'mvn clean compile'
echo ' compile finished '
}
}
stage('Test') {
steps {
echo 'Testing...'
bat 'mvn test'
echo ' sh \'mvn test\' '
}
}
stage('Package') {
steps {
echo 'Package...'
bat 'mvn package'
echo ' sh \'mvn package\' '
}
}
stage('Deploy') {
steps {
echo 'Deploying...'
echo 'sh \'mvn clean deploy\' -- 此處調(diào)用腳本或者ansible谱邪、saltstak,部署到遠(yuǎn)程 '
}
}
}
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'
}
}
}
2.2.2 方法二: 使用Jenkins file
2.2.3 也可以在pipleline腳本里面調(diào)用另外一個job
3. multibranch pipeline
創(chuàng)建多分支pipeline: