DevOps Classroom notes 04/Nov/2023

Azure DevOps Contd

Basic Maven-Java Pipeline

  • Basic Pipeline
pool: default
trigger: 
  - master

steps:
  - task: Maven@4
    inputs:
      mavenPOMFile: pom.xml
      goals: package
      publishJUnitResults: true
      testResultsFiles: '**/TEST-*.xml'
      javaHomeOption: Path
      jdkVersionOption: '1.17'
      jdkDirectory: '/usr/lib/jvm/java-17-openjdk-amd64'
      mavenVersionOption: Path
      mavenDirectory: '/usr/share/maven'

Basic dotnet core pipeline

  • dotnet core pipeline
pool: default
trigger: 
  - master
- job: dotnetbuild
    displayName: Build dotnet code
    pool: default
    steps:
      - bash: "echo staging directory $(Build.ArtifactStagingDirectory) and number $(Build.BuildNumber)"
      - bash: env
      - task: DotNetCoreCLI@2
        displayName: build the code
        inputs:
          command: build
          projects: src/NopCommerce.sln
          configuration: Release
      - task: DotNetCoreCLI@2
        displayName: publish the nopcommerce
        inputs:
          command: publish
          projects: src/Presentation/Nop.Web/Nop.Web.csproj
          zipAfterPublish: true
          configuration: Release
          arguments: "-o $(Build.ArtifactStagingDirectory)/Published"
      - task: PublishBuildArtifacts@1
        displayName: Make artifacts available
        inputs:
          PathtoPublish: $(Build.ArtifactStagingDirectory)/Published/Nop.Web.zip
          ArtifactName: 'nop'
          publishLocation: Container

Basic docker pipeline

  • Basic Pipeline
pool: default
trigger: 
  - master
stages:
  - stage: buildstage
    displayName: Build the application
    jobs:
      - job: dockerbuild
        displayName: docker image build
        pool: default
        steps:
          - task: Docker@2
            inputs:
              containerRegistry: "${{ parameters.containerRegistry }}"
              repository: shaikkhajaibrahim/nopfromado
              command: 'buildAndPush'
              Dockerfile: "$(dockerfilelocation)"
              tags: "$(Build.BuildId)"

Templates

lets create a resuable template for java based application

  • Create a new folder called as templates with a file maven-template.yaml with following content
steps:
  - task: Maven@4
    inputs:
      mavenPOMFile: pom.xml
      goals: package
      publishJUnitResults: true
      testResultsFiles: '**/TEST-*.xml'
      javaHomeOption: Path
      jdkVersionOption: '1.17'
      jdkDirectory: '/usr/lib/jvm/java-17-openjdk-amd64'
      mavenVersionOption: Path
      mavenDirectory: '/usr/share/maven'
  • Now add the following in azure-pipelines.yaml
pool: default

trigger: 
  - main

steps:
  - template: templates/maven-template.yaml


  • Now lets build the pipeline
  • Lets create template parameters
parameters:
  - name: mavenPomfile
    displayName: pom location 
    type: string
    default: pom.xml
  - name: goals
    displayName: maven goal
    type: string
    default: package
    values:
      - clean
      - compile
      - test
      - package
      - install
      - deploy
  - name: publishJUnitResults
    displayName: pom location 
    type: boolean
    default: true


steps:
  - task: Maven@4
    inputs:
      mavenPOMFile: "${{ parameters.mavenPomfile }}"
      goals: "${{ parameters.goals }}"
      publishJUnitResults: "${{ parameters.publishJUnitResults }}"
      testResultsFiles: '**/TEST-*.xml'
      javaHomeOption: Path
      jdkVersionOption: '1.17'
      jdkDirectory: '/usr/lib/jvm/java-17-openjdk-amd64'
      mavenVersionOption: Path
      mavenDirectory: '/usr/share/maven'
  • in azure-devops pipeline call template with parameters values
pool: default

trigger: 
  - main

steps:
  - template: templates/maven-template.yaml
    parameters:
      goals: 'test'

Preview

  • We have create a stages template
    Preview

Lets create an azure repo with reusable templates

  • We have create a git repo of ADO templates
    Preview
  • refer the below yaml for usage
---
trigger:
  - master

resources:
  repositories:
    - repository: templates
      name: ADOTemplates
      type: git
      ref: main



stages:
  - template: docker/docker-template.yaml@templates
    parameters:
      containerRegistry: 'mydockerhub'
      vmImage: 'ubuntu-22.04'

Preview

Activity

  • Create a pipeline for building a node js application
  • softwares:
    • git
    • nodejs (20.9.0)
    • npm
  • commands
npm install
npm run build
  • Now zip the dist file and publish artifact

Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Animated Social Media Icons by Acurax Responsive Web Designing Company

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Visit Us On FacebookVisit Us On LinkedinVisit Us On Youtube