azure devops setup package pipeline - devonfw/hangar GitHub Wiki

Setting up a Package pipeline on Azure DevOps

In this section we will create a package pipeline to build and push a container image of the project application into the specified container registry. This pipeline will be configured in order to be triggered every time quality pipeline is executed successfully on a commit for release/* and develop branches, requiring manual launch for other branches but still enforcing that quality pipeline has passed. It consumes the artifact produced by the build pipeline.

The creation of the pipeline will follow the project workflow, so a new branch named feature/package-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 this new branch, create a package pipeline based on a YAML template, 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 latest changes with git pull).

Creating the pipeline using provided script

Usage

pipeline_generator.sh \
  -c <config file path> \
  -n <{pipeline_type} name> \
  -l <language or framework> \
  --dockerfile <dockerfile path> \
  -d <project local path> \
  --build-pipeline-name <build {pipeline_type} name> \
  --quality-pipeline-name <quality {pipeline_type} name> \
  -i <image name> \
  [-u <registry user>] \
  [-p <registry password>] \
  [--aws-access-key <aws access key>] \
  [--aws-secret-access-key <aws secret access key>] \
  [--aws-region <aws region>] \
  [-b <branch>] \
  [-w]
Note
The config file for the package pipeline is located at /scripts/pipelines/azure-devops/templates/package/package-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}.
-l, --language                 [Required, if dockerfile not set] Language or framework of the project.
    --dockerfile               [Required, if language not set] Path from the root of the project to its Dockerfile. Takes precedence over the language/framework default one.
-d, --local-directory          [Required] Local directory of your project.
    --build-pipeline-name      [Required] Build {pipeline_type} name.
    --quality-pipeline-name    [Required] Quality {pipeline_type} name.
-i, --image-name               [Required] Name (excluding tag) for the generated container image.
-u, --registry-user            [Required, unless AWS or GCP] Container registry login user.
-p, --registry-password        [Required, unless AWS or GCP] Container registry login password.
    --aws-access-key           [Required, if AWS] AWS account access key ID. Takes precedence over registry credentials."
    --aws-secret-access-key    [Required, if AWS] AWS account secret access key."
    --aws-region               [Required, if AWS] AWS region for ECR."
-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

Quarkus project

Generic container registry
./pipeline_generator.sh -c ./templates/package/package-pipeline.cfg -n quarkus-project-package -l quarkus -d C:/Users/$USERNAME/Desktop/quarkus-project -i username/quarkus-project -u username -p password {extra_args_quarkus} -b develop -w
AWS ECR
./pipeline_generator.sh -c ./templates/package/package-pipeline.cfg -n quarkus-project-package -l quarkus -d C:/Users/$USERNAME/Desktop/quarkus-project -i username/quarkus-project --aws-access-key AKIAIOSFODNN7EXAMPLE --aws-secret-access-key wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY --aws-region eu-west-1 {extra_args_quarkus} -b develop -w

Node.js project

Generic container registry
./pipeline_generator.sh -c ./templates/package/package-pipeline.cfg -n node-project-package -l node -d C:/Users/$USERNAME/Desktop/node-project -i username/node-project -u username -p password {extra_args_node} -b develop -w
AWS ECR
./pipeline_generator.sh -c ./templates/package/package-pipeline.cfg -n node-project-package -l node -d C:/Users/$USERNAME/Desktop/node-project -i username/node-project --aws-access-key AKIAIOSFODNN7EXAMPLE --aws-secret-access-key wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY --aws-region eu-west-1 {extra_args_node} -b develop -w
==== Angular project
Generic container registry
./pipeline_generator.sh -c ./templates/package/package-pipeline.cfg -n angular-project-package -l angular -d C:/Users/$USERNAME/Desktop/angular-project --build-pipeline-name angular-project-build --quality-pipeline-name angular-project-quality -i username/angular-project -u username -p password -b develop -w
AWS ECR
./pipeline_generator.sh -c ./templates/package/package-pipeline.cfg -n angular-project-package -l angular -d C:/Users/$USERNAME/Desktop/angular-project --build-pipeline-name angular-project-build --quality-pipeline-name angular-project-quality -i username/angular-project --aws-access-key AKIAIOSFODNN7EXAMPLE --aws-secret-access-key wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY --aws-region eu-west-1 -b develop -w
⚠️ **GitHub.com Fallback** ⚠️