简体   繁体   中英

On-premises deployment of java code using azure ci cd

I want to deploy war files of my application to an on-premises Linux machine. I am using Azure CI/CD yaml pipeline for both build and release.

As a part of CI I am generating the artifacts and it is getting placed at the drop location.

Please see the code below for azure-pipeline.yml:

trigger:
- main

stages: 
  - stage: Build
    jobs:
      - job: BuildWebApp
        pool:
          name: LinuxAgent
          demands: maven

        steps:
        - task: Maven@3
          displayName: 'Maven pom.xml'
          inputs:
            mavenPomFile: 'pom.xml'

        - task: CopyFiles@2
          displayName: 'Copy Files to: $(build.artifactstagingdirectory)'
          inputs:
            SourceFolder: '$(system.defaultworkingdirectory)'
            Contents: '**/*.jar'
            TargetFolder: '$(build.artifactstagingdirectory)'
          condition: succeededOrFailed()

        - task: PublishBuildArtifacts@1
          displayName: 'Publish Artifact: Artfifact'
          inputs:
            PathtoPublish: '$(build.artifactstagingdirectory)'
          condition: succeededOrFailed()
          
  - stage: DeployDev
    displayName: 'Deploy to Dev'
    jobs:
      - deployment:
        pool:          
          name: LinuxAgent
        environment: 'Dev'
        strategy:
         runOnce:
           deploy:
             steps:
             - task: CopyFiles@2
               inputs:
                 SourceFolder: '$(System.DefaultWorkingDirectory)/_maven-modular.git/drop/module1/'
                 Contents: '**'
                 TargetFolder: '/home/test-user/azure-agents/test'
             

           

Can anyone please guide me if this is the right approach?

Error: ##[error]Unhandled: Not found SourceFolder: /home/test-user/azure-agents/_work/19/s/_maven-modular.git/drop/module1/target

In the deployment job, you should use the Download Build Artifacts task to download the artifacts you published in the build job to the working directory of the deployment job.

The published artifacts will not be automatically downloaded or copied to the deployment job, even if the deployment job and the build job are in the same pipeline.

You try to copy jar file, but you want to war file. Maybe it can be.

- task: CopyFiles@2
          displayName: 'Copy Files to: $(build.artifactstagingdirectory)'
          inputs:
            SourceFolder: '$(system.defaultworkingdirectory)'
            **Contents: '**/*.jar'**
            TargetFolder: '$(build.artifactstagingdirectory)'
          condition: succeededOrFailed()

As you have asked regarding the right approach - You should use a release pipeline instead of build pipeline for deployment. And as you have already published the artifacts in CI pipeline you can easily use the published artifacts in your release pipeline.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM