๐Ÿš€ Setting Up an Azure DevOps Build and Release Pipeline ๐Ÿš€

๐Ÿš€ Setting Up an Azure DevOps Build and Release Pipeline ๐Ÿš€

ยท

6 min read

In this blog post, we'll walk you through setting up an automated build and release pipeline using Azure DevOps, which will save you time and effort, and ensure consistent and error-free deployments. Let's get started with the process, step by step:

๐Ÿ—๏ธ Step 1: Build Pipeline Configuration

  1. Create a GitHub Repository:

    • If you haven't already, create a new GitHub repository or use an existing one to host your source code.

    • COPY

            https://github.com/eddzaa/NCPL.git
      
  2. Create a Build Pipeline in Azure DevOps:

    • Navigate to the Pipelines tab in your Azure DevOps project.

    • Click on "Create Pipeline."

    • Choose your GitHub repository as the source for the pipeline.

  3. Select the GitHub Repository:

    • Azure DevOps will redirect you to GitHub to select the repository you want to use.

    • After selecting the repository, click "Install" to grant Azure DevOps access to it.

  4. Modify the YAML as Needed:

    • If the auto-detected YAML meets your requirements, you can leave it as it is.

    • If you need to modify the pipeline steps, triggers, or other configurations, make the necessary changes in the YAML.

      COPY

          # 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
          #new line for CI test
      
          trigger:
          - master
      
          pool:
            vmImage: ubuntu-latest
      
          steps:
          - task: Maven@3
            inputs:
              mavenPomFile: 'pom.xml'
              mavenOptions: '-Xmx3072m'
              javaHomeOption: 'JDKVersion'
              jdkVersionOption: '1.8'
              jdkArchitectureOption: 'x64'
              publishJUnitResults: true
              testResultsFiles: '**/surefire-reports/TEST-*.xml'
              goals: 'package'
          - task: CopyFiles@2
            inputs:
              Contents: '**/*.war'
              TargetFolder: '$(build.artifactstagingdirectory)'
          - task: PublishBuildArtifacts@1
            inputs:
              PathtoPublish: '$(Build.ArtifactStagingDirectory)'
              ArtifactName: 'webapp'
              publishLocation: 'Container'
      

Monitor the Pipeline Run:

  • After triggering the pipeline, you can monitor its progress in real-time.

  • The pipeline run view will show you the individual steps being executed, their status, and any potential errors or failures.

โš™๏ธ Step 2: Create the App Service

  1. Click on "Create a resource" again, but this time, search for "App Service" in the search bar. Click on the "App Service" option from the results and then click the "Create" button.

  2. In the "Create App Service" form, you'll need to provide some essential details:

  3. Review and Create: Double-check all your settings on the "Review + create" page. If everything looks good, click on the "Create" button to start the deployment process.

  4. Once the deployment is successful, navigate to your App Service from the Azure portal. You will find the URL to access your app service, usually in the format "yourappname.azurewebsites.net."

โš™๏ธ Step 3: Release Pipeline Configuration

  • In the Azure DevOps portal, click on "Releases" and then "New pipeline."

  • Choose a template that best suits your application, or you can start with an "Empty job" for more customization.

  • In this step, you can add stages to the release pipeline, such as "Dev," "QA," and "Production." These stages represent the different environments to which your application will be deployed.

  • Now that you have set up your release pipeline and added the necessary build tasks, it's time to configure the deployment stages. Let's assume you are deploying a web application on Linux as your app type.

    1. Select Subscription: In this step, you need to choose the Azure subscription where you want to deploy your web app. If you have multiple subscriptions, ensure you select the correct one to avoid any deployment issues.

    2. Configure App Type (Web App on Linux): Since you're deploying a web application on Linux, make sure to specify this in the release pipeline configuration. This information will help Azure DevOps apply the appropriate deployment settings for your application.

    3. Next, select the "App Service name" from the available options. This would be the name of your web app service running on Linux. If you haven't created one yet, you can click on the "Create New" button to create a new web app.

  • After selecting the subscription, app type, and providing the app service name, make sure to save your configuration before proceeding to the next steps.

  • Select the source folder or .war file that contains your application files. This is typically the output folder from your build pipeline.

  • specify the files or patterns you want to include in the deployment. For a .war file, use **/*.war. For folder copy, use **/* to include all files.

  • After configuring the task to your satisfaction, click on the "Save" button to save your modifications to the stage.
  • Under the selected stage, click on the "Add" button in the "Artifacts" section. A new window will appear, prompting you to configure the source of the artifact.

  • After configuring the artifact source, click on the "Add" button to include it in your release pipeline. Save the changes and ensure that there are no validation errors.

Create a New Release

Once you have tested the pipeline and are satisfied with its performance, it's time to create a new release. Click on the "Create a release" button to initiate the deployment process.

Monitor the Deployment

Monitor the deployment progress in real-time through the Azure DevOps portal. You can view logs, check for any errors, and track the overall health of your deployment.

In the address bar, type the URL provided during the deployment process,Remember to append /webapp at the end of the URL, as specified, to ensure you are accessing the correct path for your web application.

Web application should now load, and you'll see your fantastic creation live on the internet.

  • Configure Continuous Deployment Trigger

  • In your release pipeline, navigate to the "Triggers" section for each stage. Enable the "Continuous deployment trigger" to automatically deploy to the next stage whenever a successful deployment occurs in the previous stage.

Test Continuous Deployment Trigger

  1. Make a small code change or add a new feature to your codebase. For example, you can update a text message or add a new function.

  2. Commit and push the code changes to the GitHub repository.

  3. Now, switch to the Azure DevOps portal and navigate to your project's pipeline section.

  4. Check if the Continuous Deployment trigger has been activated for your release pipeline.

  5. Finally, check the deployed application in the production environment to ensure that the code changes are successfully reflected.

https://testwebappncpl.azurewebsites.net/webapp/

๐ŸŽ‰ Congratulations! On your build and release pipelines in Azure DevOps! With an efficient build pipeline, you can generate artifacts reliably, and the release pipeline ensures smooth deployments across different environments.Happy coding! ๐Ÿ‘๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ป

Did you find this article valuable?

Support Edvin Dsouza by becoming a sponsor. Any amount is appreciated!

ย