I am trying to trigger our Gitlab pipeline with following content of TRIGGER_PAYLOAD variable using python-gitlab library:
trigger_payload = {
"project": {
"id": project_id,
"http_url": http_url,
"web_url": web_url,
"namespace": repo_namespace,
"path_with_namespace": path_with_namespace
},
"checkout_sha": commit_id,
"event_name": "tag_push"
}
# Convert the payload to a JSON string
trigger_payload_str = json.dumps(trigger_payload)
# Create a GitLab API instance
gl = gitlab.Gitlab(gitlab_url, private_token=gitlab_token)
# Get the project
project = gl.projects.get(project_id)
# Trigger the pipeline and pass the JSON payload
pipeline = project.trigger_pipeline(ref=ref, variables={'TRIGGER_PAYLOAD': trigger_payload_str})
Problem is, that TRIGGER_PAYLOAD variable is already set (as one of the default variables in GitLab) and can't be changed. I aways receive an error:
gitlab.exceptions.GitlabCreateError: 422: {'base': ['Duplicate variable name: TRIGGER_PAYLOAD']}
But when I choose different variable name, pipeline fails, because it's expecting above mentioned data structure.
How to fix it?