Skip to content

azure devops setup deploy pipeline

devonfw-core edited this page Dec 27, 2022 · 3 revisions

Setting up a Deploy pipeline on Azure DevOps

In this section we will create a deploy pipeline on Azure DevOps to deploy the project application on an already provisioned Kubernetes cluster. This pipeline will be configured in order to be triggered every time package pipeline is executed successfully on a commit for `release/*` and `develop` branches, requiring manual launch for other branches but still enforcing that package pipeline has passed. By default, it depends on the environment provisioning pipeline being successfully run on beforehand and, depending on the Kubernetes provider, it consumes the artifact produced by that. It also consumes variable groups created by package and environment provisioning pipeline.

The creation of the pipeline will follow the project workflow, so a new branch named feature/deploy-pipeline will be created and the YAML file for the pipeline will be pushed to it.

Then, a Pull Request (PR) will be created in order to merge the new branch into the appropriate branch (provided in -b flag). The PR will be automatically merged if the repository policies are met. If the merge is not possible, either the PR URL will be shown as output, or it will be opened in your web browser if using -w flag.

The script located at /scripts/pipelines/azure-devops/pipeline_generator.sh will automatically create the new branch, create a deploy pipeline based on a YAML template appropriate for the project manifests files, create the Pull Request, and if it is possible, merge this new branch into the specified branch.

Prerequisites

  • This script will commit and push the corresponding YAML template into your repository, so please be sure your local repository is up-to-date (i.e you have pulled the latest changes with git pull).

  • The YAML containing Deployment object should be named application-deployment.yaml for allowing automated imagePullSecret injection.

Creating the pipeline using provided script

Usage

pipeline_generator.sh \
  -c <config file path> \
  -n <{pipeline_type} name> \
  -d <project local path> \
  --package-pipeline-name <{pipeline_type} name> \
  --env-provision-pipeline-name <{pipeline_type} name> \
  --k8s-provider <provider name> \
  --k8s-namespace <namespace> \
  --k8s-deploy-files-path <manifests path> \
  [--k8s-image-pull-secret-name <secret name>] \
  [-b <branch>] \
  [-w]
NOTE: The config file for the deploy pipeline is located at /scripts/pipelines/azure-devops/templates/deploy/deploy-pipeline.cfg.

Flags

-c  --config-file                   [Required] Configuration file containing {pipeline_type} definition.
-n  --pipeline-name                 [Required] Name that will be set to the {pipeline_type}.
-d  --local-directory               [Required] Local directory of your project.
    --package-pipeline-name         [Required] Package {pipeline_type} name.
    --env-provision-pipeline-name   [Required] Environment provisioning {pipeline_type} name.
    --k8s-provider                  [Required] Kubernetes cluster provider name. Accepted values: EKS, AKS.
    --k8s-namespace                 [Required] Kubernetes namespace where the application will be deployed.
    --k8s-deploy-files-path         [Required] Path from the root of the project to the YAML manifests directory.
    --k8s-image-pull-secret-name               Name for the generated secret containing registry credentials. Required when using a private registry to host images.

-b  --target-branch                            Name of the branch to which the Pull Request will target. PR is not created if the flag is not provided.
-w                                             Open the Pull Request on the web browser if it cannot be automatically merged. Requires -b flag.

Examples

./pipeline_generator.sh -c ./templates/deploy/deploy-pipeline.cfg -n quarkus-project-deploy -d C:/Users/$USERNAME/Desktop/quarkus-project --package-pipeline-name quarkus-project-package --env-provision-pipeline-name eks-provisioning --k8s-provider EKS --k8s-namespace hangar --k8s-deploy-files-path k8s -b develop {openBrowserFlag}

Appendix: accessing the application

Once the pipeline is executed and your application is deployed, you can list the hostname to access it by running locally:

kubectl get ingress -n <namespace>

Guides per provider

Clone this wiki locally