Jenkins node建立html
1、jenkins搭建參考個人另一篇文章:node
http://www.cnblogs.com/cuishuai/p/7544775.htmlshell
2、搭建完成後登陸,選擇Manage Jenkinspost
接下來進入管理界面,選擇Manage Nodes:ui
選擇New Node建立新的nodespa
Node name 本身根據須要填寫便可。3d
Labels能夠指定不一樣的環境,此處我沒有寫,Host:填寫此node的內網地址,用戶名和免密碼登陸。code
最後點擊保存,建立完成。htm
接下來建立一個pipeline任務:blog
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 - 指定在哪臺機器上執行任務,還記得上面配置時候填的嗎,若是這兩個匹配得上,就在該中執行NodeLabellabelNode
· stage - 組成工做流的大的步驟,這些步驟是串行的,例如build,test,deploy等
· steps - 描述stage中的小步驟,同一個stage中的steps能夠並行
· sh - 執行shell命令
· input - 須要你手動點擊肯定,Pipeline纔會進入後續環節,經常使用於部署環節,由於不少時候部署都須要人爲的進行一些確認
· post - 全部pipeline執行完成後,會進入post環節,該環節通常作一些清理工做,同時還能夠判斷pipeline的執行狀態