Warning, /trigger-gitlab-ci/action.yml is written in an unsupported language. File is not indexed.
0001 name: "Trigger GitLab CI through webhooks"
0002 description: "Triggers the GitLab CI pipeline through webhook pipeline trigger and associated token"
0003 branding:
0004 icon: "play"
0005 color: "blue"
0006 inputs:
0007 url:
0008 description: "GitLab server url (at the level under which the API starts)"
0009 required: false
0010 default: "https://gitlab.com"
0011 project_id:
0012 description: "GitLab project ID"
0013 required: true
0014 default: ""
0015 token:
0016 description: "GitLab pipeline trigger token (GitLab Settings > CI/CD > Pipeline Triggers)"
0017 required: true
0018 default: ""
0019 ref_name:
0020 description: "GitLab project ref_name (branch or tag name; defaults to main)"
0021 required: false
0022 default: "main"
0023 variables:
0024 description: "Additional variables in VAR=value format to pass to the pipeline"
0025 required: false
0026 default: ""
0027
0028 outputs:
0029 json:
0030 description: "GitLab webhook response (JSON)"
0031 value: ${{ steps.call-webhook.outputs.json }}
0032 web_url:
0033 description: "GitLab pipeline URL"
0034 value: ${{ steps.call-webhook.outputs.web_url }}
0035
0036 runs:
0037 using: "composite"
0038 steps:
0039 - id: call-webhook
0040 run: |
0041 # Parse VARIABLES into multiple arguments
0042 variable_args=()
0043 if [[ -n "${VARIABLES}" ]]; then
0044 while IFS= read -r variable; do
0045 if [[ $variable =~ ^([a-zA-Z_][a-zA-Z0-9_]*)=(.*) ]] ; then
0046 variable_args+=("-F" "variables[${BASH_REMATCH[1]}]=${BASH_REMATCH[2]}")
0047 else
0048 echo "Unable to parse variable $variable"
0049 fi
0050 done <<< "${VARIABLES}"
0051 fi
0052 # Fail if no token
0053 test -n "${TOKEN}" || echo "::warning ::No secret token was set!"
0054 # Enable command echo
0055 set -x
0056 # Call webhook
0057 curl -X POST \
0058 --fail-with-body \
0059 -o response.json \
0060 -F "token=${TOKEN}" \
0061 -F "ref=${REF_NAME}" \
0062 "${variable_args[@]}" \
0063 ${URL}/api/v4/projects/${PROJECT_ID}/trigger/pipeline \
0064 || ( RETCODE="$?"; jq . response.json; exit "$RETCODE" )
0065 # Disable command echo
0066 set +x
0067 # Print and parse json
0068 jq . response.json
0069 {
0070 printf 'json<<__JSON__\n'
0071 cat response.json
0072 printf '\n__JSON__\n'
0073 printf 'web_url<<__URL__\n'
0074 jq --raw-output '.web_url' response.json
0075 printf '\n__URL__\n'
0076 } >> "$GITHUB_OUTPUT"
0077 shell: bash
0078 env:
0079 URL: ${{ inputs.url }}
0080 PROJECT_ID: ${{ inputs.project_id }}
0081 TOKEN: ${{ inputs.token }}
0082 REF_NAME: ${{ inputs.ref_name }}
0083 VARIABLES: ${{ inputs.variables }}