Skip to content

azure devops setup library package pipeline

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

Setting up a library package pipeline on Azure DevOps

In this section we will create a package pipeline to generate a distributable of a library and push it to a feed in Azure DevOps. 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. Depending on the language, it consumes the artifact produced by the build pipeline.

The creation of this pipeline will follow the project workflow, so a new branch named feature/library-package-pipeline will be created. The YAML file and the bash script for the pipeline will be pushed to it, as well as a generated file containing required credentials for connecting to the feed.

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 library package pipeline based on a YAML template, create the feed, create a PAT token with permission to push to that feed, 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).

Creating the pipeline using provided script

Usage

./pipeline_generator.sh \
  -c <config file path> \
  -n <pipeline name> \
  -l <language or framework> \
  -d <project local path> \
  --build-pipeline-name <build pipeline name> \
  --quality-pipeline-name <quality pipeline name> \
  [-b <branch>] \
  [-w]
Note
The config file for the library package pipeline is located at /scripts/pipelines/azure-devops/templates/library-package/library-package-pipeline.cfg.

Flags

-c, --config-file              [Required] Configuration file containing pipeline definition.
-n, --pipeline-name            [Required] Name that will be set to the pipeline.
-l, --language                 [Required] Language or framework of the project.
-d, --local-directory          [Required] Local directory of your project.
    --build-pipeline-name      [Required, if Java/Maven] Build pipeline name.
    --quality-pipeline-name    [Required] Quality pipeline name.
-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

Java project

./pipeline_generator.sh -c ./templates/library-package/library-package-pipeline.cfg -n library-package-pipeline -l java -d C:/Users/$USERNAME/Desktop/java-library-project --build-pipeline-name java-library-build --quality-pipeline-name java-library-quality

Node.js project

./pipeline_generator.sh -c ./templates/library-package/library-package-pipeline.cfg -n library-package-pipeline -l node -d C:/Users/$USERNAME/Desktop/node-library-project --quality-pipeline-name node-library-quality

Adding Maven feed to library repository list

Go to Artifacts section in Azure DevOps and select the newly created Maven feed by the script (default name is maven-feed). Then follow the Set up the Maven client guide from Azure Devops official documentation to perform required steps on the library project code side for being able to push the library from the pipeline.

Important
Ignore the settings.xml part as it is created by the script. Only pom.xml modification is needed.

Appendix

Consume library from the main project

Maven feed

Go to Azure Artifacts and click on the artifact of the library. Then copy the contents of the <dependency> element and paste it inside the <dependencies> element of your pom.xml file.

Then, follow again the Set up the Maven client guide to connect the main project to the Maven feed to be able to consume the library.

Important
Ignore the settings.xml part as is not necessary to consume an artifact. Only pom.xml modification is needed.

Guides per provider

Clone this wiki locally