import requests;
import json;
import time;
import sys, os;

#trigger pipeline in GitLab

GITLAB_TOKEN = os.environ.get('GITLAB_TOKEN')
TRIGGER_PIPELINE_URL = 'https://gitlab.com/api/v4/projects/19934840/trigger/pipeline?token=' + str(GITLAB_TOKEN) + '&ref=master'

trigger_response = requests.post(TRIGGER_PIPELINE_URL)
print(trigger_response)
pipeline_id = json.loads(trigger_response.text)['id']

#wait for pipeline to finish
status = "running";

PIPELINE_STATUS_URL = 'https://gitlab.com/api/v4/projects/19934840/pipelines/' + str(pipeline_id)
GITLAB_READ_TOKEN = os.environ.get('GITLAB_READ_TOKEN')
headers = json.dumps({'content-type': 'application/json', 'Accept-Charset': 'UTF-8', 'PRIVATE-TOKEN':  GITLAB_READ_TOKEN})
while(status == "running" or status == "pending"):
  time.sleep(30)
  response = requests.get(url=PIPELINE_STATUS_URL, headers=headers)
  print(response)
  status = json.loads(response.text)["status"]
  print(status)

if(status != "success"):
  print(status)
  sys.exit(1)

@@ -54,16 +54,17 @@
 , os;%0A%0A#
+ 
 trigger 
@@ -82,16 +82,16 @@
  GitLab%0A
-
 %0AGITLAB_
@@ -397,56 +397,55 @@
 '%5D%0A%0A
-#wait for pipeline to finish%0Astatus = %22running%22;
+%0A# prepare GET request to check pipeline status
 %0A%0API
@@ -610,20 +610,19 @@
 s = 
-json.dumps(%7B
+%7B%7D%0Aheaders%5B
 'con
@@ -631,17 +631,19 @@
 nt-type'
-:
+%5D =
  'applic
@@ -657,37 +657,17 @@
 son'
-, 'Accept-Charset': 'UTF-8', 
+%0Aheaders%5B
 'PRI
@@ -681,10 +681,11 @@
 KEN'
-: 
+%5D =
  GIT
@@ -702,10 +702,96 @@
 OKEN
-%7D)
+%0Aheaders%5B'Accept-Charset'%5D = 'UTF-8'%0A%0A# wait for pipeline to finish%0A%0Astatus = %22running%22;
 %0Awhi

Update trigger_gitlab.py