1. Introduction to Azure Pipelines
Azure Pipelines is a cloud service that automates the building and testing of your code and deploys it to any target. It works with any language, platform, and cloud.
Key Concepts:
- Triggers: Events that initiate a pipeline run (e.g., code commits, scheduled times).
- Pools: Groups of agents (virtual machines or containers) that execute pipeline jobs.
- Tasks: Pre-built or custom actions performed in a pipeline (e.g., compiling code, running tests).
- Steps: Ordered sequences of tasks within a job.
- Variables: Values that can be used throughout the pipeline to customize behavior.
- Artifacts: Files or packages produced by a pipeline run.
- YAML Syntax: Pipelines are defined using YAML (YAML Ain't Markup Language) files.
YAML Syntax Basics:
- Indentation is crucial for defining the structure.
- Key-value pairs define settings.
- Lists are defined with hyphens (
-).
2. Java (Maven) Pipeline Explained
Purpose:
This pipeline automates the build, test, and deployment of a Java project using Apache Maven.
YAML File Breakdown:
# Maven
# Build your Java project and run tests with Apache Maven.
# Add steps that analyze code, save build artifacts, deploy, and more:
# [https://docs.microsoft.com/azure/devops/pipelines/languages/java](https://docs.microsoft.com/azure/devops/pipelines/languages/java)
trigger:
- Test
pool: Server Name
steps:
- task: Maven@3
inputs:
mavenPomFile: 'JobAPI/pom.xml'
goals: 'clean compile process-resources package'
publishJUnitResults: true
testResultsFiles: '**/surefire-reports/TEST-*.xml'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.8'
mavenVersionOption: 'Default'
mavenOptions: '-Xmx3072m'
mavenAuthenticateFeed: false
effectivePomSkip: false
sonarQubeRunAnalysis: false
- task: CopyFiles@2
inputs:
SourceFolder: '$(Build.SourcesDirectory)/JobAPI'
Contents: |
pom.xml
target/*.jar
TargetFolder: '$(Build.ArtifactStagingDirectory)'
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'))
- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'))
- task: Maven@3
inputs:
mavenPomFile: 'JobAPI/pom.xml'
goals: 'deploy'
publishJUnitResults: true
testResultsFiles: '**/surefire-reports/TEST-*.xml'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.8'
mavenVersionOption: 'Default'
mavenOptions: '-Xmx3072m'
mavenAuthenticateFeed: false
effectivePomSkip: false
sonarQubeRunAnalysis: false
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'))
-
trigger: - Test: Runs the pipeline when code is pushed to theTestbranch. -
pool: ServerName: Uses a self-hosted agent pool named "Server." -
steps:: Defines the sequence of tasks.-
Maven@3(Clean, Compile, Package):-
mavenPomFile: Specifies the path to thepom.xmlfile. -
goals: Defines the Maven goals to execute (clean,compile,process-resources,package). -
publishJUnitResults: Publishes JUnit test results. -
testResultsFiles: Specifies the location of test result files. -
javaHomeOption,jdkVersionOption,mavenVersionOption,mavenOptions: Configures the Java and Maven environment.
-
-
CopyFiles@2(POM and JAR):- Copies the
pom.xmland the generated JAR file to the artifact staging directory ($(Build.ArtifactStagingDirectory)). -
condition: Prevents these tasks from running during pull requests.
- Copies the
-
PublishBuildArtifacts@1: Publishes the staged artifacts as "drop." -
Maven@3(Deploy):- Runs the maven deploy goal, to push the artifact to a maven repository.
-
-
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')): Ensures specific steps only run on successful builds and not on pull requests.
Explanation of Maven Goals and Options:
-
clean: Deletes thetargetdirectory. -
compile: Compiles the Java source code. -
process-resources: Copies resources to thetargetdirectory. -
package: Packages the compiled code into a JAR file. -
deploy: pushes the artifact to a repository. -
Xmx3072m: Allocates 3GB of memory to Maven.
Artifact Handling:
The pipeline copies the pom.xml and JAR file to the artifact staging directory and then publishes them as an artifact named "drop."
Deployment Explanation:
The second maven task with the deploy goal, will push the resulting jar file to a maven repository, that is configured inside of the pom.xml file.
3. .NET Core (.NET Framework) Pipeline Explained
Purpose:
This pipeline builds and tests an ASP.NET Core project targeting the full .NET Framework.
YAML File Breakdown:
# ASP.NET Core (.NET Framework)
# Build and test ASP.NET Core projects targeting the full .NET Framework.
# Add steps that publish symbols, save build artifacts, and more:
# [https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core](https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core)
trigger:
- Test
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller@1
- task: NuGetCommand@2
displayName: 'NuGet restore'
inputs:
command: 'restore'
restoreSolution: '$(solution)'
feedsToUse: config
nugetConfigPath: 'TTLineIMSBackoffice/NuGet.Config'
externalFeedCredentials: 'Telerik Nuget'
- task: VSBuild@1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)/WebApp.zip" /p:DeployIisAppPath="Default Web Site"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: VSTest@2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
-
trigger: - Test: Triggers the pipeline on commits to theTestbranch. -
pool: vmImage: 'windows-latest': Uses a Microsoft-hosted Windows agent. -
variables:: Defines pipeline variables.-
solution: Path to the solution file. -
buildPlatform: Build platform (Any CPU). -
buildConfiguration: Build configuration (Release).
-
-
steps::-
NuGetToolInstaller@1: Installs the NuGet tool. -
NuGetCommand@2(Restore):- Restores NuGet packages using the specified
NuGet.Configfile. -
externalFeedCredentials: provides credentials to a telerik nuget feed.
- Restores NuGet packages using the specified
-
VSBuild@1: Builds the solution using MSBuild.-
msbuildArgs: Configures the build process, including creating a web package (WebApp.zip).
-
-
VSTest@2: Runs unit tests. -
PublishBuildArtifacts@1: Publishes the build artifacts.
-

Top comments (0)