User Tools

Site Tools


gitlab-ci-release

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
gitlab-ci-release [2020/08/30 23:41]
admin created
gitlab-ci-release [2020/08/31 00:51] (current)
admin
Line 1: Line 1:
 ====== Gitlab CI create release ====== ====== Gitlab CI create release ======
 +
 +Example to create a PHP archive (phar) and link the generated artifact to the release if a **Release Note** is set.
 +
 +  * ''create_version'' Build and attach files as artifacts.
 +    * ''echo 'JOB_ARTIFACT_ID='$CI_JOB_ID > build.env'' - Will save the jobs id to env var
 +  * ''release'' Add asset link to release if tag is a release
 +    * ''export $(xargs <build.env)'' - Exports env vars set in ''build.env'' file
 +
 +**Required to create a private token and set as environment variable $GITLAB_PRIVATE_TOKEN**
 +
 +Example:
  
 <code yaml .gitlab-ci.yml> <code yaml .gitlab-ci.yml>
Line 18: Line 29:
     - composer install     - composer install
     - php -d phar.readonly=off ./vendor/bin/phar-composer -vvv build     - php -d phar.readonly=off ./vendor/bin/phar-composer -vvv build
 +    # Save variable for later use
     - echo 'JOB_ARTIFACT_ID='$CI_JOB_ID > build.env     - echo 'JOB_ARTIFACT_ID='$CI_JOB_ID > build.env
   artifacts:   artifacts:
Line 23: Line 35:
     paths:     paths:
       - $PHAR_FILE_NAME       - $PHAR_FILE_NAME
 +      # Add .env file to artifacts
       - build.env       - build.env
     expire_in: 1000 year     expire_in: 1000 year
Line 31: Line 44:
   dependencies:    dependencies: 
     - create_version     - create_version
 +  when: on_success
   only:   only:
     - tags     - tags
Line 36: Line 50:
     # Get variables saved as artifacts in `.phar` template     # Get variables saved as artifacts in `.phar` template
     - export $(xargs <build.env)     - export $(xargs <build.env)
 +    # Create release if a 'Release Note' was set while creating a tag
     - 'curl --request POST --header "PRIVATE-TOKEN: $GITLAB_PRIVATE_TOKEN"     - 'curl --request POST --header "PRIVATE-TOKEN: $GITLAB_PRIVATE_TOKEN"
       --data name="$PHAR_ARTIFACT_NAME-$CI_COMMIT_TAG.phar"        --data name="$PHAR_ARTIFACT_NAME-$CI_COMMIT_TAG.phar" 
       --data url="$CI_SERVER_URL/api/v4/projects/$CI_PROJECT_ID/jobs/$JOB_ARTIFACT_ID/artifacts/$PHAR_FILE_NAME"        --data url="$CI_SERVER_URL/api/v4/projects/$CI_PROJECT_ID/jobs/$JOB_ARTIFACT_ID/artifacts/$PHAR_FILE_NAME" 
       $CI_SERVER_URL/api/v4/projects/$CI_PROJECT_ID/releases/$CI_COMMIT_TAG/assets/links'       $CI_SERVER_URL/api/v4/projects/$CI_PROJECT_ID/releases/$CI_COMMIT_TAG/assets/links'
- 
 </code> </code>
gitlab-ci-release.1598823691.txt.gz ยท Last modified: 2020/08/30 23:41 by admin