This blog explains how to configure Spinnaker v1.16.1 to trigger a continuous delivery pipeline based on commits in the Gitlab repository and inject changed Gitlab files as artifacts into the Spinnaker pipeline.
1. Prerequisites for setting GitLab triggered Spinnaker pipeline
1.1. GitLab account
Create a new project in GitLab and then add some sample artifact files to the Repository.
Artifact file(manifest.yaml) should not include the tag details for the Docker image.
1.2. A running Spinnaker instance.
2. Configure GitLab Webhook for Spinnaker pipeline
Steps to configure GitLab Webhook:
1. Navigate to the Settings page of a repository
2. Choose the Integrations menu
3. Fill out the fields:
3.1. URL: http://<Public-IP>:8084/webhooks/webhook/gitlab
The Payload URL should be $ENDPOINT/webhooks/webhook/gitlab. We need Spinnaker’s API running on an endpoint that is publicly reachable. This is required to allow GitLab’s webhooks to reach Spinnaker. If you’re unsure of what your Spinnaker API endpoint is, check the value of services.gate.baseUrl in ~/.hal/$DEPLOYMENT/staging/spinnaker.yml.
The value of $DEPLOYMENT is typically default.
3.2. Secret Token: Spinnaker validates the source of the requests with the Secret Token
4. Select Trigger options like, ‘Push events’, ‘Tag Push events’, etc.
5. Check/Uncheck ‘Enable SSL verification’ according to Spinnaker server SSL configuration
6. Click ‘Add webhook’.
3. Configure a GitLab Artifact Account
Spinnaker can be configured to listen to changes to a repository in GitLab. These steps show you how to configure a GitLab artifact account so that Spinnaker can download files from GitLab.
3.1. Downloading Credentials
Start by generating an access token for GitLab. The token requires the repo scope. Here Create an access token for GitLab by following the below link:
Generate an Access token for GitLab account and downloaded credentials are saved in a file called, ‘gitlab_token_file’. TOKEN_FILE=/home/opsmxuser/dvrs/gitlab_token_file
3.2. Editing Artifact Settings in Spinnaker Config
Enable GitLab artifact support and add an artifact account(Ex: dvr-gitlab-artifact-act):
TOKEN_FILE=/home/opsmxuser/dvrs/gitlab_token_file ARTIFACT_ACCOUNT_NAME=dvr-gitlab-artifact-act $ hal config features edit --artifacts true $ hal config artifact gitlab enable $ hal config artifact gitlab account add $ARTIFACT_ACCOUNT_NAME --token-file $TOKEN_FILE $ hal deploy apply
4. Configure Spinnaker Pipeline Trigger
Configure Spinnaker pipeline to be triggered by a GitLab commit:
4.1. Configuration Stage in Spinnaker Pipeline
Create a new pipeline that we want it to be triggered on changes to GitLab Repository/artifacts.
1. In Pipeline configuration, click the Configuration stage on the far left of the pipeline diagram.
2. Click on Add Artifact under Expected Artifacts
3. Select an artifact account that was added earlier (3.2) from the Account drop down list and enter the File Path field with a manifest file.
4. Select ‘Use Default Artifact’ and specify the artifact account that was added earlier (3.2) from the Account drop-down list and the ‘Content URL’.
Here the ‘Content URL’ is used as:
5. Add one more Artifact Account for Docker-Registry as an account and the Docker image name that we want to trigger on changes to.
6. Click Automated Triggers.
7. In the Type field, select Webhook.
8. In the Source field, select GitLab. This input determines the target URL required to trigger this pipeline, as well as how the payload can be transformed into artifacts.
4.2. Deploy Kubernetes Manifests using Spinnaker pipeline
4.2.1 Select the Deploy (Manifest) stage by specifying the manifests. Add manifest configuration to read manifest file content from an artifact created upstream and the expected artifact must be referenced here and will be bound at run time.
4.2.2 Select the Display name of the Expected artifact account for Manifest Artifact. The artifact that is to be applied to the Kubernetes account for this stage. The artifact should represent a valid Kubernetes manifest.
4.2.3 Select the Display name of the docker-registry account for ‘Required Artifacts to Bind’.
5.1 Make a change into the repository, https://gitlab.com/vijayendar/dvrgitlabproj/tree/master, and ensure Spinnaker’s pipeline is auto-triggered. This can also be verified under Settings -> Integrations -> Webhooks -> Test -> Push events by checking the response for Hook executed successfully: HTTP 200, which means the GitLab event has been processed successfully.
5.2 Ensure the Deploy(manifest) stage is executed successfully as shown below:
And click on Tasks Status for checking the status of tasks of Google Cloud Build.
5.3 And see the subsequent result in Kubernetes cluster as below:
If you want to know more about the Spinnaker or request a demonstration, please book a meeting with us.
OpsMx is a leading provider of Continuous Delivery solutions that help enterprises safely deliver software at scale and without any human intervention. We help engineering teams take the risk and manual effort out of releasing innovations at the speed of modern business. For additional information, contact us