Skip to content

Latest commit

 

History

History
127 lines (100 loc) · 3.54 KB

use-dev-proxy-with-azure-pipelines.md

File metadata and controls

127 lines (100 loc) · 3.54 KB
title description author ms.author ms.date
Use Dev Proxy with Azure Pipelines
How to use Dev Proxy with Azure Pipelines.
waldekmastykarz
wmastyka
05/28/2024

Use Dev Proxy with Azure Pipelines

Using Dev Proxy with Azure Pipelines is a great way to test your applications in a controlled environment. Following these steps, you can use Dev Proxy with your Azure Pipelines.

Note

In this article, we use an Ubuntu agent for Azure Pipelines.

Install Dev Proxy and cache it

Start, by installing Dev Proxy on the agent, but do it only if it isn't already installed. To install and cache Dev Proxy, add the following steps to your pipeline file:

variables:
- name: DEV_PROXY_VERSION
  value: v0.18.0-beta.8
- name: DEV_PROXY_CACHE_RESTORED
  value: 'false'

steps:
- task: Cache@2
  inputs:
    key: '"dev-proxy-$(DEV_PROXY_VERSION)"'
    path: ./devproxy
    cacheHitVar: DEV_PROXY_CACHE_RESTORED
  displayName: Cache Dev Proxy

- script: bash -c "$(curl -sL https://aka.ms/devproxy/setup-beta.sh)" $DEV_PROXY_VERSION
  displayName: 'Install Dev Proxy beta'
  condition: ne(variables.DEV_PROXY_CACHE_RESTORED, 'true')

Run the Dev Proxy

When you run Dev Proxy in a CI/CD pipeline, you need to start it from a script, so that you can close it gracefully. When you have your script ready, invoke it in your pipeline file:

- script: bash ./run.sh
  displayName: 'Run Dev Proxy'

Upload Dev Proxy logs as artifacts

When you run Dev Proxy in a CI/CD pipeline, you might want to analyze the logs later. To keep Dev Proxy logs, you can upload them as artifacts:

- task: PublishPipelineArtifact@1
  displayName: Upload Dev Proxy logs
  inputs:
    targetPath: $(LOG_FILE)
    ArtifactName: $(LOG_FILE)

Upload Dev Proxy reports

If you're using Dev Proxy to analyze the requests, you might want to upload the reports as artifacts as well:

- script: |
    mkdir -p $(Build.ArtifactStagingDirectory)/Reports
    find . -name "*Reporter*" -exec cp {} $(Build.ArtifactStagingDirectory)/Reports \;
  displayName: 'Copy reports to artifact directory'
- task: PublishPipelineArtifact@1
  displayName: Upload Dev Proxy reports
  inputs:
    targetPath: '$(Build.ArtifactStagingDirectory)/Reports'
    artifactName: 'Reports'

Example pipeline file

Here's an example of a pipeline file that installs Dev Proxy, runs it, and uploads the logs and reports as artifacts:

trigger:
- main
- dev

pool:
  vmImage: ubuntu-latest

variables:
- name: LOG_FILE
  value: devproxy.log
- name: DEV_PROXY_VERSION
  value: v0.18.0
- name: DEV_PROXY_CACHE_RESTORED
  value: 'false'

steps:
- task: Cache@2
  inputs:
    key: '"dev-proxy-$(DEV_PROXY_VERSION)"'
    path: ./devproxy
    cacheHitVar: DEV_PROXY_CACHE_RESTORED
  displayName: Cache Dev Proxy

- script: bash -c "$(curl -sL https://aka.ms/devproxy/setup-beta.sh)" $DEV_PROXY_VERSION
  displayName: 'Install Dev Proxy beta'
  condition: ne(variables.DEV_PROXY_CACHE_RESTORED, 'true')

- script: bash ./run.sh
  displayName: 'Run Dev Proxy'

- task: PublishPipelineArtifact@1
  displayName: Upload Dev Proxy logs
  inputs:
    targetPath: $(LOG_FILE)
    ArtifactName: $(LOG_FILE)

- script: |
    mkdir -p $(Build.ArtifactStagingDirectory)/Reports
    find . -name "*Reporter*" -exec cp {} $(Build.ArtifactStagingDirectory)/Reports \;
  displayName: 'Copy reports to artifact directory'
- task: PublishPipelineArtifact@1
  displayName: Upload Dev Proxy reports
  inputs:
    targetPath: '$(Build.ArtifactStagingDirectory)/Reports'
    artifactName: 'Reports'