Jenkins Pipeline Docker Agent Setup Dynamically

半世苍凉 提交于 2019-12-05 03:26:18

问题


In declarative pipelines we set up docker agent as below,

pipeline {
  agent {  
   docker {
    image dockerImage
    args dockerArgs
    registryUrl dockerRegistryUrl
    registryCredentialsId dockerRegistryCredentialsId
    label dockerLabel
    alwaysPull true
   }
  }
....

but I want to do something like this,

def dockerAgent = new Docker(dockerImage, dockerArgs,...)

pipeline {
 agent {  
    dockerAgent
    }
}
....

The intention is to generate Docker Agent with the properties using a shard-lib and inject the agent to the pipeline. Is this possible to do?

来源:https://stackoverflow.com/questions/49248617/jenkins-pipeline-docker-agent-setup-dynamically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!