Back to home page

EIC code displayed by LXR

 
 

    


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         # Enable command echo
0053         set -x
0054         # Call webhook
0055         curl -X POST \
0056              --fail-with-body \
0057              -o response.json \
0058              -F "token=${TOKEN}" \
0059              -F "ref=${REF_NAME}" \
0060              "${variable_args[@]}" \
0061              ${URL}/api/v4/projects/${PROJECT_ID}/trigger/pipeline \
0062              || ( RETCODE="$?"; jq . response.json; exit "$RETCODE" )
0063         # Disable command echo
0064         set +x
0065         # Print and parse json
0066         jq . response.json
0067         echo "json<<END" >> $GITHUB_OUTPUT
0068         cat response.json >> $GITHUB_OUTPUT
0069         echo "END" >> $GITHUB_OUTPUT
0070         echo "web_url<<END" >> $GITHUB_OUTPUT
0071         cat response.json | jq --raw-output '.web_url' >> $GITHUB_OUTPUT
0072         echo "END" >> $GITHUB_OUTPUT
0073       shell: bash
0074       env:
0075         URL: ${{ inputs.url }}
0076         PROJECT_ID: ${{ inputs.project_id }}
0077         TOKEN: ${{ inputs.token }}
0078         REF_NAME: ${{ inputs.ref_name }}
0079         VARIABLES: ${{ inputs.variables }}