Use GitLab API from GitLabCI script assembly

I have a GitLab CI script assembly as follows:

create release: stage: deploy tags: - basic only: - tags script: - GITLOG=$(echo "# Changes Log"; git log `git tag | tail -2 | head -1`..${CI_BUILD_TAG} --pretty=format:" - %s") - curl -X POST -d "private_token=$CI_BUILD_TOKEN&description=$GITLOG" "http://git.example.com/api/v3/projects/${CI_PROJECT_ID}/repository/tags/${CI_BUILD_TAG}/release" 

The goal of this step is to automatically add the change log from Git to the GitLab Releases section.

This works if I manually run this on the command line and put in variables ...

The problem is that the value of CI_BUILD_TOKEN in the running line is not a valid personal GitLab token - it is only a token for connecting to the docker registry - according to the documentation.

Is there a way to get a valid GitLab API token that the build runner can use to access the API for the project that is building? It seems like it should be possible.

GitLab Runner:

 gitlab-runner -v Version: 1.2.0 Git revision: 3a4fcd4 Git branch: HEAD GO version: go1.6.2 Built: Sun, 22 May 2016 20:05:30 +0000 OS/Arch: linux/amd64 
+12
gitlab gitlab-ci gitlab-ci-runner
source share
2 answers

You can have read- only access with the API from the runner, but only if you add the header with CI_JOB_TOKEN .

eg

 curl -H "JOB_TOKEN: $CI_JOB_TOKEN" "https://gitlab.com/api/v4/projects/2828837/repository/tags 

And only when the project is public, everyone has access from the same project.

If you want to access both private projects and / or recordings, please vote for the release of GitLab No. 29566 and / or No. 41084 .

Alternatively, at the moment, you can create an access token on gitlab and add it to the secret variables in the project settings / ci_cd, although this is not recommended, since your personal token will be used by everyone who runs the task.,

+13
source share

Have you tried using secret variables ? You can define in the settings, and then use a script in your assembly.

0
source share

All Articles