jenkins-pipline-agent使用,使构建能够在不同环境,不同容器中运行
生活随笔
收集整理的這篇文章主要介紹了
jenkins-pipline-agent使用,使构建能够在不同环境,不同容器中运行
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
jenkins agent
參考地址https://www.jenkins.io/doc/book/pipeline/syntax/
該agent部分指定整個(gè)Pipeline或特定階段將在Jenkins環(huán)境中執(zhí)行的位置,具體取決于該agent 部分的放置位置。該部分必須在pipeline塊內(nèi)的頂層定義 ,但階段級(jí)使用是可選的。
簡單來說,agent部分主要作用就是告訴Jenkins,選擇那臺(tái)節(jié)點(diǎn)機(jī)器去執(zhí)行Pipeline代碼。這個(gè)指令是必須要有的,也就在你頂層pipeline {…}的下一層,必須要有一個(gè)agent{…},agent這個(gè)指令對(duì)應(yīng)的多個(gè)可選參數(shù),本篇文章會(huì)一一介紹。這里注意一點(diǎn),在具體某一個(gè)stage {…}里面也可以使用agent指令。這種用法不多,一般我們?cè)陧攲邮褂胊gent,這樣,接下來的全部stage都在一個(gè)agent機(jī)器下執(zhí)行代碼。
#參數(shù)1:any 作用:在任何可用的代理上執(zhí)行Pipeline或stage pipeline {agent anyparameters {gitParameter branchFilter: 'origin/(.*)', defaultValue: 'dev', name: 'BRANCH', type: 'PT_BRANCH'}stages{stage("git clone"){steps {script {sh """"""}}}stage("git clone"){steps {}}stage("git clone"){steps {}}} }參數(shù)2:none 當(dāng)在pipeline塊的頂層應(yīng)用時(shí),將不會(huì)為整個(gè)Pipeline運(yùn)行分配全局代理,并且每個(gè)stage部分將需要包含其自己的agent部分。 pipeline {agent anyparameters {gitParameter branchFilter: 'origin/(.*)', defaultValue: 'dev', name: 'BRANCH', type: 'PT_BRANCH'}stages{stage("git clone"){agent {label 'jenkins-git'}steps {script {sh """"""}}}stage("git build"){agent {label 'jenkins-jdk'}steps {}}stage("deploy"){agent {label 'jenkins-sync'}steps {}}} }//參數(shù)3:label 作用:使用提供的標(biāo)簽在Jenkins環(huán)境中可用的代理機(jī)器上執(zhí)行Pipeline或stage內(nèi)執(zhí)行。 pipeline {agent {label 'jenkins-dev'} } //參數(shù)4:node 作用:和上面label功能類似,但是node運(yùn)行其他選項(xiàng),例如customWorkspace pipeline {agent {node {label 'jenkins-agent-node1'customWorkspace "${env.JOB_NAME}/${env.BUILD_NUMBER}"}} }//其實(shí)agent相關(guān)的還有兩個(gè)可選參數(shù),分別是docker和dockerfile//第一種全部在一個(gè)節(jié)點(diǎn)和 容器內(nèi)運(yùn)行 在節(jié)點(diǎn)jenkins-dev 上運(yùn)行 golang:1.17-alpine容器掛載目錄 pipeline {agent {docker { label 'jenkins-dev'image 'golang:1.17-alpine' args "-v ${SSH_KEY_PATH}:${SSH_CREDENTIAL_PATH}"}}parameters {gitParameter branchFilter: 'origin/(.*)', defaultValue: 'dev', name: 'BRANCH', type: 'PT_BRANCH'}stages{stage("git clone"){steps {script {sh """"""}}}stage("git build"){agent {label 'jenkins-jdk'}steps {}}stage("deploy"){agent {label 'jenkins-sync'}steps {}}} }//使用多個(gè)容器 pipeline {agent nonestages {stage('git pull') {agent {docker{ image 'git:latest' }}steps {sh 'git version'}}stage('build'){agent {docker{ image 'node:7-alpine' }}steps {sh 'node --version'}}} }總結(jié)
以上是生活随笔為你收集整理的jenkins-pipline-agent使用,使构建能够在不同环境,不同容器中运行的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 用C语言求排列组合数
- 下一篇: scrapy爬取某宝心得