airflow.providers.jenkins.operators.jenkins_job_trigger
¶
Module Contents¶
Classes¶
Trigger a Jenkins Job and monitor its execution. |
Functions¶
|
Create a Jenkins request from a raw request. |
Attributes¶
- airflow.providers.jenkins.operators.jenkins_job_trigger.jenkins_request_with_headers(jenkins_server, req)[source]¶
Create a Jenkins request from a raw request.
We need to get the headers in addition to the body answer to get the location from them. This function uses
jenkins_request
from python-jenkins with just the return call changed.- Parameters
jenkins_server (jenkins.Jenkins) – The server to query
req (requests.Request) – The request to execute
- Returns
Dict containing the response body (key body) and the headers coming along (headers)
- Return type
JenkinsRequest
- class airflow.providers.jenkins.operators.jenkins_job_trigger.JenkinsJobTriggerOperator(*, jenkins_connection_id, job_name, parameters=None, sleep_time=10, max_try_before_job_appears=10, allowed_jenkins_states=None, **kwargs)[source]¶
Bases:
airflow.models.BaseOperator
Trigger a Jenkins Job and monitor its execution.
This operator depend on the python-jenkins library version >= 0.4.15 to communicate with the Jenkins server. You’ll also need to configure a Jenkins connection in the connections screen.
- Parameters
jenkins_connection_id (str) – The jenkins connection to use for this job
job_name (str) – The name of the job to trigger
parameters (ParamType) – The parameters block provided to jenkins for use in the API call when triggering a build. (templated)
sleep_time (int) – How long will the operator sleep between each status request for the job (min 1, default 10)
max_try_before_job_appears (int) – The maximum number of requests to make while waiting for the job to appears on jenkins server (default 10)
allowed_jenkins_states (collections.abc.Iterable[str] | None) – Iterable of allowed result jenkins states, default is
['SUCCESS']
- template_fields: collections.abc.Sequence[str] = ('parameters',)[source]¶
- template_ext: collections.abc.Sequence[str] = ('.json',)[source]¶
- build_job(jenkins_server, params=None)[source]¶
Trigger a build job.
This returns a dict with 2 keys
body
andheaders
.headers
contains also a dict-like object which can be queried to get the location to poll in the queue.- Parameters
jenkins_server (jenkins.Jenkins) – The jenkins server where the job should be triggered
params (ParamType) – The parameters block to provide to jenkins API call.
- Returns
Dict containing the response body (key body) and the headers coming along (headers)
- Return type
JenkinsRequest
- poll_job_in_queue(location, jenkins_server)[source]¶
Poll the jenkins queue until the job is executed.
When we trigger a job through an API call, the job is first put in the queue without having a build number assigned. We have to wait until the job exits the queue to know its build number.
To do so, we add
/api/json
(or/api/xml
) to the location returned by thebuild_job
call, and poll this file. When anexecutable
block appears in the response, the job execution would have started, and the fieldnumber
would contains the build number.