Jenkins node創建
1、jenkins搭建參考我的另外一篇文章:
http://www.cnblogs.com/cuishuai/p/7544775.html
2、搭建完成后登錄,選擇Manage Jenkins
接下來進入管理界面,選擇Manage Nodes:
選擇New Node創建新的node
Node name 自己根據需要填寫即可。
Labels可以指定不同的環境,此處我沒有寫,Host:填寫此node的內網地址,用戶名和免密碼登錄。
最后點擊保存,創建完成。
接下來創建一個pipeline任務:
pipeline {
agent {label 'spark' }
stages {
stage('userlogs') {
steps {
dir('/data/scripts'){
sh 'sh userlogs.sh'
}
}
}
stage('es_userlogs') {
steps {
dir('/data/scripts'){
sh 'sh es_userlogs.sh'
}
}
}
}
}
lable 可以寫node的name,如果Lables處填寫了,此處就可以寫那個值了。
例子:
pipeline {
agent {
label 'Production'
}
stages {
stage('Build') {
steps {
echo 'Building'
}
}
stage('Test') {
steps {
echo 'Testing'
}
}
stage('Deploy - Staging') {
steps {
sh './deploy staging'
sh './run-smoke-tests'
}
}
stage('Sanity check') {
steps {
input "Does the staging environment look ok?"
}
}
stage('Deploy - Production') {
steps {
sh './deploy production'
}
}
}
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...'
}
}
}
· agent - 指定在哪台機器上執行任務,還記得上面配置Node
時候填的Label
嗎,如果這兩個label
匹配得上,就在該Node
中執行
· stage - 組成工作流的大的步驟,這些步驟是串行的,例如build,test,deploy等
· steps - 描述stage中的小步驟,同一個stage中的steps可以並行
· sh - 執行shell命令
· input - 需要你手動點擊確定,Pipeline才會進入后續環節,常用於部署環節,因為很多時候部署都需要人為的進行一些確認
· post - 所有pipeline執行完成后,會進入post環節,該環節一般做一些清理工作,同時還可以判斷pipeline的執行狀態