如何在免费的奴隶上运行Jenkins脚本化管道作业?

时间:2018-11-05 15:56:29

标签: jenkins continuous-integration jenkins-pipeline

我想在没有其他作业在其上运行时在指定的从属服务器上运行Jenkins脚本化管道作业。 我的工作开始后,不应在此从属服务器上执行其他任何工作,它们将不得不等待我的工作结束运行

我发现的所有教程都允许我在空闲时在节点上运行作业,但并不能保护我免于在该节点上启动其他作业

你能告诉我该怎么做吗?

1 个答案:

答案 0 :(得分:1)

因为管道有两个语法,所以有两种方法可以实现。对于脚本化管道,请检查第二个管道。

声明性

pipeline {
    agent none
    stages {
        stage('Build') {
            agent { label 'slave-node​' }
            steps {
                echo 'Building..'
                sh '''
                '''
            }
        }
    }

    post {
        success {
            echo 'This will run only if successful'
        }
    }
}

脚本化

node('your-node') {
  try {

    stage 'Build'
    node('build-run-on-this-node') {
        sh ""
    }
  } catch(Exception e) {
    throw e
  }
}