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 while IFS= read -r variable; do
0044 if [[ $variable =~ ^([a-zA-Z_][a-zA-Z0-9_]*)=(.*) ]] ; then
0045 variable_args+=("-F" "variables[${BASH_REMATCH[1]}]=${BASH_REMATCH[2]}")
0046 else
0047 echo "Unable to parse variable $variable"
0048 fi
0049 done <<< "${VARIABLES}"
0050 # Fail if no token
0051 test -n "${TOKEN}" || echo "::warning ::No secret token was set!"
0052 # Print webhook call
0053 echo curl -X POST \
0054 --fail \
0055 -o response.json \
0056 -F "token=${TOKEN}" \
0057 -F "ref=${REF_NAME}" \
0058 "${variable_args[@]}" \
0059 ${URL}/api/v4/projects/${PROJECT_ID}/trigger/pipeline
0060 # Call webhook
0061 curl -X POST \
0062 --fail \
0063 -o response.json \
0064 -F "token=${TOKEN}" \
0065 -F "ref=${REF_NAME}" \
0066 "${variable_args[@]}" \
0067 ${URL}/api/v4/projects/${PROJECT_ID}/trigger/pipeline \
0068 || ( RETCODE="$?"; jq . response.json; exit "$RETCODE" )
0069 # Print and parse json
0070 jq . response.json
0071 echo "json<<END" >> $GITHUB_OUTPUT
0072 cat response.json >> $GITHUB_OUTPUT
0073 echo "END" >> $GITHUB_OUTPUT
0074 echo "web_url<<END" >> $GITHUB_OUTPUT
0075 cat response.json | jq --raw-output '.web_url' >> $GITHUB_OUTPUT
0076 echo "END" >> $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 }}