乐闻世界logo
搜索文章和话题

What is the Agent Directive in Jenkins?

2月7日 00:15

In Jenkins, the agent directive specifies the environment where Jenkins should execute the entire pipeline or specific stages. It can be any available node, such as a specific server, a group of servers, or execution within a Docker container.

For example:

groovy
pipeline { agent none // Not executed on any agent stages { stage('Build') { agent { docker 'maven:3-alpine' } steps { sh 'mvn clean install' } } stage('Test') { agent { label 'my-defined-label' } steps { sh 'mvn test' } } } }

In this example, the Build stage executes within a specified Docker container, while the Test stage executes on a node configured with the label my-defined-label. This approach provides high flexibility and control, allowing the selection of the most suitable execution environment for different stages.

标签:Jenkins