Skip to content

Commit

Permalink
finish
Browse files Browse the repository at this point in the history
  • Loading branch information
mojib committed Apr 7, 2024
1 parent 22728d4 commit 1e298a8
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 15 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Test
on:
push:
workflow_dispatch:

jobs:
test:
runs-on: ubuntu-latest
name: Tests

steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4

- name: Build & Lint
run: |
npm ci
npm run build
npm run lint
55 changes: 54 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,60 @@
# gitlab-cd-trigger
# GitLab CD Pipeline trigger

Github Action to trigger Gitlab CD pipeline

[GitHub](https://github.com/mb-wali/gitlab-cd-trigger) |
[GitHub Marketplace](https://github.com/marketplace/actions/gitlab-cd-trigger)

[![Test action](https://github.com/mb-wali/gitlab-cd-trigger/actions/workflows/main.yml/badge.svg)](https://github.com/mb-wali/gitlab-cd-trigger/actions/workflows/main.yml)

This GitHub action triggers and waits for a [GitLab pipeline](https://docs.gitlab.com/ee/ci/pipelines/) to complete.

You can for example use this action in your GitHub workflow to trigger a deployment pipeline on a private
GitLab server after a successful build pipeline and wait for the deployment (with possible End2End tests)
to finish, so you would get a notification if the deployment failed.

## Inputs

### `URL`

The GitLab URL to trigger the pipeline on. Default `gitlab.com`.

### `PROJECT_ID`

**Required** The ID or path of the project owned by the authenticated user.
You will find the *Project ID* in the *General Settings* of your GitLab project.

### `REF_NAME`

**Required** The branch or tag to run the pipeline on.

### `GITLB_TRIGGER_TOKEN`

**Required** The [GitLab pipeline trigger token](https://docs.gitlab.com/ee/ci/triggers/index.html#create-a-trigger-token)
to trigger the pipeline.


### `PIPELINE_VARIABLES`

A map of key-valued strings containing the pipeline variables. For example: `{ VAR1: "value1", VAR2: "value2" }`.. Default `"World"`.

## Outputs

### `web_url`

The URL of the pipeline, for example `https://gitlab.com/foo/bar/pipelines/47`.

## Example usage

```yaml
uses: digital-blueprint/gitlab-pipeline-trigger-action@v1
with:
URL: 'gitlab.example.com'
GITLB_TRIGGER_TOKEN: ${{ secrets.DEPLOY_TRIGGER_TOKEN }}
PROJECT_ID: '123'
REF_NAME: 'main'
PIPELINE_VARIABLES: '{"VAR1":"value1","VAR2":"value2"}'
```
https://github.com/digital-blueprint/gitlab-pipeline-trigger-action
https://www.youtube.com/watch?v=N26xgQ7kLKo
19 changes: 13 additions & 6 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ branding:
color: 'orange'
inputs:
PROJECT_ID:
description: 'The ID of the GitLab project'
description: 'The ID or URL-encoded path of the project owned by the authenticated user.'
required: true
default: ''
GITLB_TRIGGER_TOKEN:
Expand All @@ -15,17 +15,24 @@ inputs:
default: ''
REF_NAME:
description: 'The GitLab branch or tag name'
required: true
default: ''
required: false
default: 'main'
URL:
description: 'The GitLab URL'
required: false
default: 'gitlab.com'
PIPELINE_VARIABLES:
description: 'A map of key-valued strings containing the pipeline variables. For example: { VAR1: "value1", VAR2: "value2" }.'
required: false
# access_token:
# description: 'Pipeline Access Token, see https://docs.gitlab.com/ee/user/project/settings/project_access_tokens.html'
# required: false
# default: ''
outputs:
status:
description: 'The status of the pipeline.'
# status:
# description: 'The status of the pipeline.'
web_url:
description: 'The URL of the pipeline.'
runs:
using: 'node18'
using: 'node20'
main: 'dist/index.js'
16 changes: 8 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ const pollPipeline = async (host, projectId, token, pipelineId, webUrl) => {
}

async function run() {
const host = encodeURIComponent(core.getInput('host'));
const projectId = encodeURIComponent(core.getInput('id'));
const triggerToken = core.getInput('trigger_token');
const accessToken = core.getInput('access_token');
const ref = core.getInput('ref');
const variables = JSON.parse(core.getInput('variables'));
const host = encodeURIComponent(core.getInput('URL'));
const projectId = encodeURIComponent(core.getInput('PROJECT_ID'));
const triggerToken = core.getInput('GITLB_TRIGGER_TOKEN');
// const accessToken = core.getInput('access_token');
const ref = core.getInput('REF_NAME');
const variables = JSON.parse(core.getInput('PIPELINE_VARIABLES'));

console.log(`Triggering pipeline ${projectId} with ref ${ref} on ${host}!`);

Expand Down Expand Up @@ -109,8 +109,8 @@ async function run() {
core.setOutput("web_url", data.web_url);
console.log(`Pipeline id ${data.id} triggered! See ${data.web_url} for details.`);

// poll pipeline status
await pollPipeline(host, projectId, accessToken, data.id, data.web_url);
// // poll pipeline status
// await pollPipeline(host, projectId, accessToken, data.id, data.web_url);
} catch (error) {
core.setFailed(error.message);
}
Expand Down

0 comments on commit 1e298a8

Please sign in to comment.