Reputation: 810
I am able to successfully create a release with the GitLab API but I am trying to create an additional asset that has a link in the release, package.zip. The release currently has the entire code as a zip but I am wanting to create a zip out of a subset of the repo.
Reading here: https://docs.gitlab.com/ee/user/project/releases/index.html#permanent-links-to-release-assets
It looks like I needed to do something similar to the following:
if __name__ == '__main__':
url = "https://gitlab.com/api/v4/projects/12345678/releases"
headers = {'PRIVATE-TOKEN': os.environ['CI_JOB_TOKEN']}
data = {'tag_name': 'Lite-Release',
'assets': {
'links': [{
'name': 'link_test',
'url': 'https://gitlab.com/api/v4/projects/12345678/releases/Lite-Release/downloads',
'filepath': '/package.zip', 'link_type': 'other'}]
}}
post_resp = requests.post(url, headers=headers, data=data)
print(post_resp.text)
This returns the error: {"error":"assets is invalid"}
What am I missing here?
Is the url
field supposed to be what I want the url to be or what?
Edit: It does not appear to be a JSON formatting issue as the following works fine and creates a release.
if __name__ == '__main__':
url = "https://gitlab.com/api/v4/projects/12345678/releases"
headers = {'PRIVATE-TOKEN': os.environ['PRIVATE_TOKEN']}
data = {'tag_name': 'tag_test', 'ref': 'HEAD'}
post_resp = requests.post(url, headers=headers, data=data)
print(post_resp.text)
Upvotes: 2
Views: 942
Reputation: 21
Did the same as you using curl, compared the data json, and everything seems ok.
Had previously problems with the CI_JOB_TOKEN, which can create a release (as stated in the docs - https://docs.gitlab.com/ee/api/README.html#gitlab-cicd-job-token), however it has not enough privileges to include assets - got a 401, instead of the error message you get. Might be a difference in the Gitlab server version..
By using a Personal Access Token I was able to make the creation of a release with package asset possible.
Upvotes: 2
Reputation: 1625
When creating a release via API the data is a JSON-object.
The JSON standard requires double quotes and will not accept single quotes.
Upvotes: -1