User Tools

Site Tools


gitlab-ci-composer-publish

This is an old revision of the document!


Gitlab Composer Packages publish using Runner

Minimal config

Works without any further modification

stages:
    - publish

publish:
    image: curlimages/curl:latest
    stage: publish
    variables:
        URL: "$CI_SERVER_PROTOCOL://$CI_SERVER_HOST:$CI_SERVER_PORT/api/v4/projects/$CI_PROJECT_ID/packages/composer?job_token=$CI_JOB_TOKEN"
    script:
        - version=$([ -z "$CI_COMMIT_TAG" ] && echo "branch=$CI_COMMIT_REF_NAME" || echo "tag=$CI_COMMIT_TAG")
        - insecure=$([ "$CI_SERVER_PROTOCOL" -eq "http"] && echo "--insecure" || echo "")
        - response=$(curl -s -w "\n%{http_code}" $insecure --data $version $URL)
        - code=$(echo "$response" | tail -n 1)
        - body=$(echo "$response" | head -n 1)
        # Output state information
        - if [ $code -eq 201 ];
            then
                echo "Package created - Code $code - $body";
            else
                echo "Could not create package - Code $code - $body";
                exit 1;
            fi

Extended config

Make sure to adjust test:script block according to your needs.

stages:
    - test
    - publish

test:
    image: composer:2
    stage: test
    script:
        - composer install
        - vendor/bin/codecept run --html
    artifacts:
        paths:
            - tests/_output/report.html
        expire_in: 1 weeks

publish:
    image: curlimages/curl:latest
    stage: publish
    variables:
        URL: "$CI_SERVER_PROTOCOL://$CI_SERVER_HOST:$CI_SERVER_PORT/api/v4/projects/$CI_PROJECT_ID/packages/composer?job_token=$CI_JOB_TOKEN"
    script:
        - version=$([ -z "$CI_COMMIT_TAG" ] && echo "branch=$CI_COMMIT_REF_NAME" || echo "tag=$CI_COMMIT_TAG")
        - response=$(curl -s -w "\n%{http_code}" --insecure --data $version $URL)
        - code=$(echo "$response" | tail -n 1)
        - body=$(echo "$response" | head -n 1)
        # Output state information
        - if [ $code -eq 201 ];
            then
                echo "Package created - Code $code - $body";
            else
                echo "Could not create package - Code $code - $body";
                exit 1;
            fi
gitlab-ci-composer-publish.1592730987.txt.gz · Last modified: 2020/06/21 11:16 by admin