Are project CI settings accessible via the API?

We have a script that uses the python API library to set up new projects and apply our standard settings (e.g. developer and master branches for all new projects are created and protected). We need to make some standard changes to our CI settings to each project but I can’t see these available in the API, am I right that this has to be done manually?

e.g the Settings tab from the project page, then CI/CD Settings and untick “Skip outdated deployment jobs”

Hi, maybe this?

https://docs.gitlab.com/ee/api/projects.html#edit-project

ci_forward_deployment_enabled boolean No When a new deployment job starts, skip older deployment jobs that are still pending.

closest thing I could find in API docs.

3 Likes

Thank you very much, I searched the documents but didn’t find that! I must not have used a sensible search term :slight_smile:

1 Like

One more question if I may - we use the python gitlab CLI utility in our script and I can’t work out how to update this setting via the CLI. I can retrieve its current value but I haven’t been able to change it. Do you have any idea please?

Not got a working python example, but you basically want to do a PUT - as per the docs:

PUT /projects/:id

replace $PASSWD with your access-token to gain access/login. And replace xx in the URL with the ID number of the project.

curl --header "PRIVATE-TOKEN: $PASSWD" -X PUT https://gitlab.mydomain.com/api/v4/projects/xx?ci_forward_deployment_enabled=false

maybe something like that, haven’t tested the format exactly to see if that would work.

You can omit the header stuff, and use login/password in the URL, but I find it more secure by access-token. Eg: https://username:password@gitlab.mydomain.com

This link gives some examples: API Docs | GitLab eg:

curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/namespaces?per_page=50"

so similar to my format above. Other alternative is POST instead of PUT.

Failing that try:

curl -X PUT -d "ci_forward_deployment_enabled=false" https://gitlab.mydomain.com/api/v4/projects/xx

of course add the auth stuff like my other URL, but it’s another option for passing data if the first one doesn’t work.

And you can do a GET request to get all the project ID’s and then loop it in to update for example all projects in one go, enabling/disabling the option you want.

If it was me in python I would just do

import requests
mytoken = "my-token"
headers = {'PRIVATE-TOKEN': mytoken}
url = "https://gitlab.mydomain.com/api/v4/projects/xx"
mydata = {'ci_forward_deployment_enabled': 'false'}
requests.post(url, data=mydata, headers=headers)

as a rough example, and could rework it into a function.