联系:node, agent以及slave都用来指被Jenkins master管理的用来执行Jenkins jobs的服务器。
区别:agents用在表述性pipeline中,可以不仅仅是nodes,还可以是docker container等。
nodes用在脚本化pipeline中。
表述性pipeline
所有操作都在pipeline块中执行,格式如下:
pipeline
{
//pipeline can be defined here
}
脚本化pipeline
绝大多数操作都在node中执行,格式如下:
node{
stage("A"){
}
// ... stages
}
Agent在表述性pipeline中的应用
agent必须在pipeline的顶端定义,也可在stage的顶端定义。例如
pipeline {
agent none
stages {
stage("Stage A") {
agent any
} // stage
stage("Stage B") {
agent { label 'my-defined-label' }
} //stage
} // stages
}
Node在脚本化pipeline中的应用
在脚本pipeline中,一个或者多个node块来完成整个pipeline的核心工作。在脚本pipeline中,node并不是必须的。但是,node中的pipeline可以完成两样工作:
1. 一个块就是一个queue,只要node中又可用的executor,则块中的模块就会执行。
2. 创建工作区间。
node {
stage('Build') {
//
}
stage('Test') {
//
}
stage('Deploy') {
//
}
}
node {
stage('ReBuild') {
//
}
stage('ReTest') {
//
}
stage('ReDeploy') {
//
}
}
本文详细阐述了Jenkins中node,agent及slave的概念及其在不同pipeline类型中的应用。对比了表述性pipeline与脚本化pipeline的特点,介绍了如何使用agent和node进行任务调度与资源分配,为读者提供了深入理解Jenkins自动化构建流程的视角。
3282

被折叠的 条评论
为什么被折叠?



