Cloud Services

Enterprise Marketplace

DevOps and CI/CD tool configuration to work with GitOps
Published On Sep 20, 2024 - 12:19 PM

DevOps and CI/CD tool configuration to work with GitOps

Setting up DevOps and CI/CD tools to work with GitOps.
Before you can use GitOps to control your pipelines, you need to configure your DevOps and CI/CD tools to integrate with it. This process involves the following steps:
For additional details, see Examples of working with Jenkins.

Configuring your pipelines

After you have identified the pipelines that will be listed to request from Kyndryl Modern Operations Applications, follow your CI/CD system's documentation to generate and configure your CI/CD pipeline webhook URL/secret into your Git repository for approved orders.
The order information that is sent to your CI/CD pipelines after approval is called the
Request Form
. This form contains the configuration parameters and values that have been selected by the user (i.e. Buyer) in Enterprise Marketplace when configuring the order.

Enabling DevOps pipeline reporting

After an order is placed and your CI/CD pipelines have processed the order successfully, you can enable the DevOps pipeline to report the order tracking status to Kyndryl Modern Operations Applications. The CI/CD pipeline can update the order tracking information located in the
GitHub repository for GitOps content and submitted orders not yet approved
folder. The order directory will be available in the
Orders
branch. The CI/CD pipeline can also update the value of the status parameter to
Completed
in order to let Kyndryl Modern Operations Applications know that all proccessing is complete for this order.

Examples of working with Jenkins

The following is an example Job definition in Jenkins for parsing the values from the
Request Form
for a single configuration parameter called "app" that is assigned a value by the user in Kyndryl Modern Operations Applications.
BRANCH=RELEASE \ && cd /opt/build/mcmpgitopsrelease \ && echo "updating build for branch ${BRANCH}..." \ && git fetch --tags \ && echo "git reset branch ${BRANCH}..." \ && git reset --hard \ && git checkout "${BRANCH}" \ && echo "checkout complete for branch ${BRANCH}..." \ && git pull \ && echo "pull complete for ${BRANCH}..." \ && printf '\n' \ && echo "$(date) - updated branch ${BRANCH}..." \ && FORM=$(file='./mcmporders' && \ while read file; do echo $(git log --pretty=format:%ad -n 1 --date=raw -- $file) $file; done < <(git ls-tree -r --name-only HEAD) | sort -k1,1n | awk 'END{print}' | awk '{print $3}') \ && APP=$(cat $FORM | jq '.app') \ && sudo docker stop $APP || true \ && sudo docker rm $APP || true \ && CMD="sudo docker run -d --restart=always -p 80:80 $APP" \ && echo $CMD \ && eval $CMD
The following example shows how you can define your Jenkins job to report the success/failure status to the user in Enterprise Marketplace. After the Jenkins Job has finished processing, it will be able to commit the status of the operation to the GitOps integration repos, which drives the remaining lifecycle of the order on Enterprise Marketplace. When this process is complete, the user is notified.
#!/bin/bash cd /tmp && rm -rf mcmp-gitops-release && git clone https://mcmpdemo:[email protected]/mcmpdemoeng/mcmp-gitops-release.git \ && BRANCH=RELEASE \ && ls /$WORKSPACE \ && cd /tmp/mcmp-gitops-release \ && ls /tmp/mcmp-gitops-release \ && echo "updating build for branch ${BRANCH}..." \ && git fetch --tags \ && echo "git reset branch ${BRANCH}..." \ && git reset --hard \ && git checkout "${BRANCH}" \ && echo "checkout complete for branch ${BRANCH}..." \ && git pull \ && echo "pull complete for ${BRANCH}..." \ && printf '\n' \ && echo "$(date) - updated branch ${BRANCH}..." \ && FORM=$(file='./mcmporders' && while read -r file; do echo "$(git log --pretty=format:%ad -n 1 --date=raw -- "$file")" "$file"; done < <(git ls-tree -r --name-only HEAD) | sort -k1,1n | awk 'END{print}' | awk '{print $3}') \ && ORDER=$(echo $FORM | cut -d/ -f1) \ && echo "Retreiving parameters for Order# $ORDER" \ && TFSATE=$(cat $FORM | jq '.deployment_status') \ && param1=$(cat $FORM | jq '.param1') \ && param2=$(cat $FORM | jq '.param2') \ && password=$(cat $FORM | jq '.password') \ && echo "Got Terraform State" \ && echo $TFSATE \ && echo "Got user defined configuration parameters" \ && echo $param1 \ && echo $param2 \ && echo $password \ && echo "Got credentials" \ && echo "#####################################################################################" \ && echo "#####################################################################################" \ && echo "Running deployment" \ && echo "You can run shell commands in this job using eval $CMD & use parameters sent by Enterprise Marketplace" \ && echo "set -ex ensures the job errors out if any step fails" \ && set -ex \ && CMD="do_something $param1 $param2" \ && echo $CMD \ && echo "#####################################################################################" \ && echo "App Installation completed..." \ && echo "#####################################################################################" \ && cd /tmp && rm -rf mcmp-gitops-content && git clone https://mcmpdemo:[email protected]/mcmpdemoeng/mcmp-gitops-content.git \ && cd /tmp/mcmp-gitops-content \ && git checkout Orders \ && echo "#####################################################################################" \ && echo "Processing Enterprise Marketplace order updates for Order# $ORDER" \ && echo "#####################################################################################" \ && ORDER=$(echo $FORM | cut -d/ -f1) \ && jq '.status="Completed"' "/tmp/mcmp-gitops-content/mcmporders/$ORDER/orderStatusTracking.json" > "/tmp/mcmp-gitops-content/mcmporders/$ORDER/orderStatusTracking.json.tmp" \ && mv "/tmp/mcmp-gitops-content/mcmporders/$ORDER/orderStatusTracking.json.tmp" "/tmp/mcmp-gitops-content/mcmporders/$ORDER/orderStatusTracking.json" \ && rm -f "/tmp/mcmp-gitops-content/mcmporders/$ORDER/orderStatusTracking.json.tmp" \ && git add -A \ && git add . \ && echo "#####################################################################################" \ && git commit -m "Successfully updated order status for Order# $ORDER" \ && echo "#####################################################################################" \ && git push -u origin Orders \ && echo "App deployment job for Order# $ORDER completed successfully!"
Do you have two minutes for a quick survey?
Take Survey