User Tools

Site Tools


gitlab-ci-composer-publish

Differences

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

Link to this comparison view

Next revision
Previous revision
gitlab-ci-composer-publish [2020/06/19 23:25] – created admingitlab-ci-composer-publish [2020/06/21 21:19] (current) admin
Line 1: Line 1:
 ====== Gitlab Composer Packages publish using Runner ====== ====== Gitlab Composer Packages publish using Runner ======
  
-Token: Set variable ''PERSONAL_TOKEN'' in your project's Settings -> CI/CD -> Variables 
  
 ===== Minimal config ===== ===== Minimal config =====
 +
 +Works without any further modification
  
 <code yaml> <code yaml>
-stages: +# Publishes a tag/branch to Composer Packages of the current project
-    - publish +
 publish: publish:
-    image: curlimages/curl:latest +  image: curlimages/curl:latest 
-    stage: publish +  stage: build 
-    script: +  variables: 
-        if [ -z "$CI_COMMIT_TAG" ]+    URL: "$CI_SERVER_PROTOCOL://$CI_SERVER_HOST:$CI_SERVER_PORT/api/v4/projects/$CI_PROJECT_ID/packages/composer?job_token=$CI_JOB_TOKEN" 
-            then +  script: 
-                export PACKAGE_VERSION="branch=$CI_COMMIT_REF_NAME"+    version=$([[ -z "$CI_COMMIT_TAG" ]] && echo "branch=$CI_COMMIT_REF_NAME" || echo "tag=$CI_COMMIT_TAG") 
-            else +    insecure=$("$CI_SERVER_PROTOCOL" = "http" ] && echo "--insecure"
-                export PACKAGE_VERSION="tag=$CI_COMMIT_TAG"; +    - response=$(curl --w "\n%{http_code}" $insecure --data $version $URL) 
-            fi +    - code=$(echo "$response| tail -n 1) 
-        if [ $(curl --write-out %{http_code} --silent --output /dev/null --insecure --data $PACKAGE_VERSION "http://__token__:$PERSONAL_TOKEN@$CI_SERVER_HOST:3000/api/v4/projects/$CI_PROJECT_ID/packages/composer") = "201" ]; +    - body=$(echo "$response| head -n 1) 
-            then +    # Output state information 
-                echo "Package created ..."; +    - if [ $code -eq 201 ]; then 
-            else +        echo "Package created - Code $code - $body"; 
-                echo "Could not create package ..."; +      else 
-                exit 1; +        echo "Could not create package - Code $code - $body"; 
-            fi+        exit 1; 
 +      fi
 </code> </code>
  
 ===== Extended config ===== ===== Extended config =====
 +
 +Make sure to adjust ''test:script'' block according to your needs.
  
 <code yaml> <code yaml>
 stages: stages:
-    - test +  - test 
-    publish+  build
  
 test: test:
-    image: composer:+  image: composer:
-    stage: test +  stage: test 
-    script: +  script: 
-        - composer install +    - composer install 
-        - vendor/bin/codecept run --html +    - vendor/bin/codecept run --html 
-    artifacts: +  artifacts: 
-        paths: +    paths: 
-            - tests/_output/report.html +      - tests/_output/report.html 
-        expire_in: 1 weeks+    expire_in: 1 weeks
  
 +# Publishes a tag/branch to Composer Packages of the current project
 publish: publish:
-    image: curlimages/curl:latest +  image: curlimages/curl:latest 
-    stage: publish +  stage: build 
-    script: +  variables: 
-        if [ -z "$CI_COMMIT_TAG" ]+    URL: "$CI_SERVER_PROTOCOL://$CI_SERVER_HOST:$CI_SERVER_PORT/api/v4/projects/$CI_PROJECT_ID/packages/composer?job_token=$CI_JOB_TOKEN" 
-            then +  script: 
-                export PACKAGE_VERSION="branch=$CI_COMMIT_REF_NAME"+    version=$([[ -z "$CI_COMMIT_TAG" ]] && echo "branch=$CI_COMMIT_REF_NAME" || echo "tag=$CI_COMMIT_TAG") 
-            else +    insecure=$("$CI_SERVER_PROTOCOL" = "http" ] && echo "--insecure"
-                export PACKAGE_VERSION="tag=$CI_COMMIT_TAG"; +    - response=$(curl --w "\n%{http_code}" $insecure --data $version $URL) 
-            fi +    - code=$(echo "$response| tail -n 1) 
-        if [ $(curl --write-out %{http_code} --silent --output /dev/null --insecure --data $PACKAGE_VERSION "http://__token__:$PERSONAL_TOKEN@$CI_SERVER_HOST:3000/api/v4/projects/$CI_PROJECT_ID/packages/composer") = "201" ]; +    - body=$(echo "$response| head -n 1) 
-            then +    # Output state information 
-                echo "Package created ..."; +    - if [ $code -eq 201 ]; then 
-            else +        echo "Package created - Code $code - $body"; 
-                echo "Could not create package ..."; +      else 
-                exit 1; +        echo "Could not create package - Code $code - $body"; 
-            fi +        exit 1; 
 +      fi
 </code> </code>
  
gitlab-ci-composer-publish.1592609110.txt.gz · Last modified: 2020/06/19 23:25 by admin