jenkins 批量禁用job
时间: 2023-11-24 11:38:45 浏览: 59
你可以通过 Jenkins 的 REST API 批量禁用 Job。以下是一个使用 Python requests 库实现的示例代码:
```python
import requests
# Jenkins credentials
username = 'your_username'
password = 'your_password'
# Jenkins base URL
jenkins_url = 'http://your_jenkins_url'
# API endpoint for disabling a job
disable_job_endpoint = '/job/{job_name}/disable'
# Jobs to be disabled
jobs_to_disable = ['job1', 'job2', 'job3']
# Iterate through jobs and disable them
for job_name in jobs_to_disable:
# Construct the API endpoint URL
endpoint_url = jenkins_url + disable_job_endpoint.format(job_name=job_name)
# Send a POST request to disable the job
response = requests.post(endpoint_url, auth=(username, password))
# Print the response status code
print(f'{job_name} disabled with status code {response.status_code}')
```
你需要将上面的代码中的 `your_username`,`your_password` 和 `your_jenkins_url` 替换成你的 Jenkins 凭证和 Jenkins URL。还需要将 `jobs_to_disable` 列表替换成你想要禁用的 Job 名称列表。