jenkins pipeline agent step
时间: 2023-08-29 22:05:52 浏览: 112
Jenkins Pipeline's `agent` step is used to allocate a Jenkins agent (also known as a slave or node) to execute the stages of your pipeline. The `agent` step specifies where the pipeline should run, whether on the Jenkins master or on a specific agent with the required capabilities.
Here is an example of how to use the `agent` step in a Jenkins Pipeline:
```groovy
pipeline {
agent {
// Specify the type of agent and its label
label 'my-agent'
}
stages {
// Define your pipeline stages here
stage('Build') {
steps {
// Steps for the build stage
}
}
stage('Test') {
steps {
// Steps for the test stage
}
}
// Add more stages as needed
}
}
```
In this example, the `agent` step specifies that the pipeline should run on an agent with the label `'my-agent'`. You can replace `'my-agent'` with the label of a specific agent you have configured in your Jenkins environment.
By using the `agent` step, you can distribute the workload of your pipeline across multiple agents, allowing for parallel execution of stages and better resource utilization.
阅读全文