blob: ccbdc489e4c78beafc871fcea288f31680edd81e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
---
##
# Search for a job id
# with name: artifact_job_name
# limit to pipeline if artifact_in_pipeline (default: true)
##
- name: set empty fact for job
set_fact:
job: {}
artifact_in_pipeline: "{{ artifact_in_pipeline | default(true) }}"
- name: get job id in this pipeline
when: artifact_in_pipeline | bool
block:
- name: "Get job successful job ids of the pipeline"
uri:
url: >-
{{ gitlab.api_url }}/projects/{{
lookup( 'env', 'CI_PROJECT_ID') }}/pipelines/{{
lookup( 'env', 'CI_PIPELINE_ID') }}/jobs?scope[]=success
method: GET
headers:
PRIVATE-TOKEN: "{{ gitlab.private_token }}"
register: pipeline_success_jobs
- name: get the job id
set_fact:
job: >-
{{ { 'id':
pipeline_success_jobs.json |json_query(
'[?name==`'+ artifact_job_name + ':' +
inventory_hostname +'`].id') | last
} }}
- name: fetch the job id corresponding to get_artifact value if not in pipeline
include_tasks: job_id_fetch.yml
loop: "{{ range(0, job_id_fetch.max_page)| list }}"
when: not (artifact_in_pipeline | bool )
loop_control:
loop_var: page
- name: check we found an artifact job id
fail:
msg: 'We can not found a correct job id'
when: job.id is not defined
- name: get last successful job id
set_fact:
artifact_job_ids: "{{ (artifact_job_ids|default([])) + [job.id] }}"
|