jenkins-node
Jenkins node创建1、jenkins搭建参考我的另外一篇文章:
http://www.cnblogs.com/cuishuai/p/7544775.html
2、搭建完成后登录,选择Manage Jenkins
https://images2017.cnblogs.com/blog/1200972/201711/1200972-20171115155559687-67323079.png
接下来进入管理界面,选择Manage Nodes:
https://images2017.cnblogs.com/blog/1200972/201711/1200972-20171115155608921-1458558488.png
https://images2017.cnblogs.com/blog/1200972/201711/1200972-20171115155625859-648957413.png
选择New Node创建新的node
https://images2017.cnblogs.com/blog/1200972/201711/1200972-20171115155634390-762572192.png
Node name 自己根据需要填写即可。
https://images2017.cnblogs.com/blog/1200972/201711/1200972-20171115155644312-1966273101.png
Labels可以指定不同的环境,此处我没有写,Host:填写此node的内网地址,用户名和免密码登录。
https://images2017.cnblogs.com/blog/1200972/201711/1200972-20171115155652218-1709751228.png
最后点击保存,创建完成。
接下来创建一个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的执行状态
页:
[1]