mirror of
https://github.com/tektoncd/catalog.git
synced 2024-11-21 05:55:35 +00:00
Add Gitlab Release task
This task can be used to make a release on the Gitlab. Assets or binaries of the released version can also be uploaded with the release. Signed-off-by: Divyansh42 <diagrawa@redhat.com>
This commit is contained in:
parent
6b7cf32a82
commit
265c6fe380
56
gitlab/create-gitlab-release/README.md
Normal file
56
gitlab/create-gitlab-release/README.md
Normal file
@ -0,0 +1,56 @@
|
||||
# Create Gitlab Release
|
||||
|
||||
It is typical to create a Gitlab tag at the moment of release to introduce a checkpoint in your source code history,
|
||||
but in most cases users will need compiled objects or other assets output, not just the raw source code.
|
||||
|
||||
Gitlab Releases are a way to track deliverables in your project. Consider them a snapshot in time of the source,
|
||||
build output, artifacts, and other metadata associated with a released version of your code.
|
||||
|
||||
This `task` can be used to make the `gitlab release`.
|
||||
|
||||
Task can also be used to upload `assets` including `binaries` of the released version, with the release.
|
||||
|
||||
## Install the Task
|
||||
|
||||
```
|
||||
kubectl apply -f https://raw.githubusercontent.com/tektoncd/catalog/v1beta1/gitlab/create-gitlab-release/create-gitlab-release.yaml
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
- **TAG_NAME**: A git tag name that will be created with this release(_e.g:_`v1.0.0`).
|
||||
- **NAME**: The Name of the release (_e.g:_`First release`).
|
||||
- **DESCRIPTION**: A short description of the release (_default:_`""`).
|
||||
- **RELEASE_REF**: It can be a commit SHA, another tag name, or a branch name (_default:_`master`).
|
||||
- **PROJECT_ID**: The Gitlab id of the project, can be found on the repository page of the gitlab (_e.g:_`18587362`)
|
||||
- **UPLOAD_ASSET_NAME**: The name of the asset that needs to be uploaded (_default:_`""`).
|
||||
- **UPLOAD_ASSET_URL**: The uplaod URL for the hosted asset (_default:_`""`).
|
||||
- **GITLAB_TOKEN_SECRET**: The name of the `secret` holding the gitlab-token (_default:_`gitlab-token`).
|
||||
- **GITLAB_TOKEN_SECRET_KEY**: The name of the `secret key` holding the gitlab-token (_default:_`GITLAB_TOKEN`).
|
||||
|
||||
|
||||
## Secrets
|
||||
* `Secret` to provide personal `access token` of the Gitlab.
|
||||
|
||||
Check [this](https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html) to get personal access token for `Gitlab`.
|
||||
|
||||
## Usage
|
||||
|
||||
This task expects a secret named gitlab-token to exists, with a Gitlab personal access token in `GITLAB_TOKEN` with enough privileges to create a release.
|
||||
|
||||
At present, `Gitlab` doesn't provide the functionality to upload any file to the release directly, however file that is hosted on any platform (i.e `aws s3` or `gitlab`) can be uploaded with the release by providing the hosted file `URL path` as the param to the task.
|
||||
|
||||
To make a release put all the required params in the Taskrun, add required secrets and release will be done.
|
||||
|
||||
`Secrets` can be created as follows:
|
||||
```
|
||||
apiVersion: v1
|
||||
kind: Secret
|
||||
metadata:
|
||||
name: gitlab-token
|
||||
type: Opaque
|
||||
stringData:
|
||||
GITLAB_TOKEN: $(personal-gitlab-token)
|
||||
```
|
||||
|
||||
This [example](../gitlab/create-gitlab-release/example/run.yaml) can be referred to create Taskrun for Gitlab release.
|
81
gitlab/create-gitlab-release/create-gitlab-release.yaml
Normal file
81
gitlab/create-gitlab-release/create-gitlab-release.yaml
Normal file
@ -0,0 +1,81 @@
|
||||
apiVersion: tekton.dev/v1beta1
|
||||
kind: Task
|
||||
metadata:
|
||||
name: create-gitlab-release
|
||||
spec:
|
||||
params:
|
||||
- name: TAG_NAME
|
||||
description: Name of the tag.
|
||||
type: string
|
||||
- name: NAME
|
||||
description: Name of the release.
|
||||
type: string
|
||||
- name: DESCRIPTION
|
||||
type: string
|
||||
description: Short description of the release.
|
||||
default: ""
|
||||
- name: RELEASE_REF
|
||||
type: string
|
||||
description: Required in the case of Gitlab, It can be a commit SHA, another tag name, or a branch name.
|
||||
default: master
|
||||
- name: PROJECT_ID
|
||||
type: string
|
||||
description: Project id for gitlab project.
|
||||
- name: UPLOAD_ASSET_NAME
|
||||
type: string
|
||||
description: Name of the asset to be uploaded.
|
||||
default: ""
|
||||
- name: UPLOAD_ASSET_URL
|
||||
type: string
|
||||
description: Uplaod URL for the hosted asset.
|
||||
default: ""
|
||||
- name: GITLAB_TOKEN_SECRET
|
||||
type: string
|
||||
description: Name of the secret holding the gitlab-token.
|
||||
default: gitlab-token
|
||||
- name: GITLAB_TOKEN_SECRET_KEY
|
||||
type: string
|
||||
description: Name of the secret key holding the gitlab-token.
|
||||
default: GITLAB_TOKEN
|
||||
steps:
|
||||
- name: create-release
|
||||
image: registry.access.redhat.com/ubi8/ubi-minimal:latest
|
||||
script: |
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Creating asset json if file is to be uploaded with gitlab release
|
||||
#
|
||||
assetJson=""
|
||||
# Checking whether asset is provided to upload with release or not.
|
||||
#
|
||||
if [ "$(params.UPLOAD_ASSET_NAME)" != "" ] || [ "$(params.UPLOAD_ASSET_URL)" != "" ]; then
|
||||
assetJson=',"assets": {"links": [{"name": "$(params.UPLOAD_ASSET_NAME)","url": "$(params.UPLOAD_ASSET_URL)"}]}'
|
||||
fi
|
||||
|
||||
# Creating the api post data
|
||||
#
|
||||
generate_api_post_data()
|
||||
{
|
||||
cat <<EOF
|
||||
{
|
||||
"name": "$(params.NAME)",
|
||||
"tag_name": "$(params.TAG_NAME)",
|
||||
"description": "$(params.DESCRIPTION)",
|
||||
"ref": "$(params.RELEASE_REF)"
|
||||
$assetJson
|
||||
}
|
||||
EOF
|
||||
}
|
||||
|
||||
echo "Creating release $(params.TAG_NAME)"
|
||||
|
||||
curl --header 'Content-Type: application/json' --header "PRIVATE-TOKEN:$TOKEN" \
|
||||
--data "$(generate_api_post_data)" \
|
||||
--request POST https://gitlab.com/api/v4/projects/$(params.PROJECT_ID)/releases
|
||||
|
||||
env:
|
||||
- name: TOKEN
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: $(params.GITLAB_TOKEN_SECRET)
|
||||
key: $(params.GITLAB_TOKEN_SECRET_KEY)
|
26
gitlab/create-gitlab-release/example/run.yaml
Normal file
26
gitlab/create-gitlab-release/example/run.yaml
Normal file
@ -0,0 +1,26 @@
|
||||
apiVersion: tekton.dev/v1beta1
|
||||
kind: TaskRun
|
||||
metadata:
|
||||
name: create-gitlab-release-run
|
||||
spec:
|
||||
taskRef:
|
||||
name: create-gitlab-release
|
||||
params:
|
||||
- name: TAG_NAME
|
||||
value: "v1.0.0"
|
||||
- name: NAME
|
||||
value: first release
|
||||
- name: DESCRIPTION
|
||||
value: This is first release
|
||||
- name: PROJECT_ID
|
||||
value: "18587362"
|
||||
- name: RELEASE_REF
|
||||
value: master
|
||||
- name: UPLOAD_ASSET_NAME
|
||||
value: test.yaml
|
||||
- name: UPLOAD_ASSET_URL
|
||||
value: https://google.com
|
||||
- name: GITLAB_TOKEN_SECRET
|
||||
value: gitlab-token
|
||||
- name: GITLAB_TOKEN_SECRET_KEY
|
||||
value: GITLAB_TOKEN
|
7
gitlab/create-gitlab-release/example/secret.yaml
Normal file
7
gitlab/create-gitlab-release/example/secret.yaml
Normal file
@ -0,0 +1,7 @@
|
||||
apiVersion: v1
|
||||
kind: Secret
|
||||
metadata:
|
||||
name: gitlab-token
|
||||
type: Opaque
|
||||
stringData:
|
||||
GITLAB_TOKEN: $(personal-gitlab-token)
|
Loading…
Reference in New Issue
Block a user