.gitlab-ci.yml and saving API endpoint values in variables?

Good day, I have a variable as follows in my .gitlab-ci.yml file:

$PIPELINE_ID = (Invoke-RestMethod -Uri 'https://gitlab.example/api/v4/projects/1/pipelines/latest').id

Is this the correct way to capture values from the JSON response from that API call into a variable? This is the full response:

{
 "id":10210,
 "iid":1659,
 "project_id":12,
 ...
}

Thanks for any tips / help

Hi @Calicoder

Variables are just strings, you cannot execute subshell commands in them.

If you need to get Pipeline ID the job is part of you can use one of many Predefined variables reference | GitLab

1 Like

Perfect, thank you for the tip