Jenkins Pipeline Docker Agent Setup Dynamically

2019-04-02 04:04发布

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?

0条回答
登录 后发表回答