Azure DevOps
The only core ABCD-Lite ready-made task is available for Azure DevOps pipelines for now. It can be installed from the Visual Studio marketplace: https://marketplace.visualstudio.com/items?itemName=1node.abcd-lite.
In addition to the existing ones in your project, you'll need the following tasks:
- ABCD Lite - used for communicating with ABCD Lite and initializing deployment.
- ORAS CLI - used to login to the container registry and push artifacts
ORAS CLI Installation
ORAS CLI can be installed in Azure DevOps by using the next task template:
- task: CmdLine@2
name: install_oras
displayName: Download ORAS bin
inputs:
script: |
VERSION="1.2.3"
curl -LO "https://github.com/oras-project/oras/releases/download/v${VERSION}/oras_${VERSION}_linux_amd64.tar.gz"
mkdir -p oras/
tar -zxf oras_${VERSION}_*.tar.gz -C oras/
rm -rf oras_${VERSION}_*.tar.gz
Any further actions, such as logging into the container registry and pushing artifacts, will be performed using the ORAS CLI. An example of its usage can be found in the pipeline example below.
Globally, for the pipeline to work correctly, you need to create a variable group with the following variables before starting:
- REGISTRY_USERNAME - login for container registry
- REGISTRY_PASSWORD - password or token from container registry with push permissions
- ABCDLITE_DEPLOY_TOKEN - ABCD Lite deployment token
Make sure the listed variables in the variable group are marked as sensitive.
Other values are not sensitive and can be set in the pipeline variables for convenience.
Deployment template
You can get pre-filled step template by clicking on Azure DevOps icon near the IIS site name on the project card.
Pipeline Example
In this pipeline, compared to the template generated by ABCD Lite, some changes have been made, specifically: some values have been moved to the pipeline variables for ease of use.
Warning
Do not forget to update pipeline variable values before using this template.
Warning
This deployment template will remove everything from the deployment folder except exclusions.
trigger: none
pool:
vmImage: ubuntu-latest
variables:
- group: Sun-system
- name: csproj
value: "Venus.Presentation/Venus.Presentation.csproj"
- name: sln
value: "Venus.sln"
- name: projectName
value: Venus.Presentation
- name: REGISTRY_URL
value: docker.io
- name: ARTIFACT_REPOSITORY
value: acme/venus
- name: ABCD_LITE_URL
value: https://abcd.acme.com
- name: ABCD_LITE_PROJECT_ID
value: c75595d0-f592-433b-86e6-372cbbe6c413
- name: ABCD_LITE_SITE_NAME
value: venus.acme.com
stages:
- stage: Build
displayName: Build
jobs:
- job: Build
displayName: Build
pool:
vmImage: ubuntu-latest
steps:
- task: DotNetCoreCLI@2
name: nuget_restore
displayName: NuGet Restore
inputs:
command: 'restore'
projects: '$(sln)'
- task: DotNetCoreCLI@2
name: dotnet_build
displayName: Build
inputs:
command: 'build'
projects: '$(csproj)'
arguments: '-c Release'
- task: DotNetCoreCLI@2
name: dotnet_publish
displayName: Publish
inputs:
command: 'publish'
publishWebProjects: false
projects: '$(csproj)'
arguments: '-c Release /p:EnvironmentName=Production -o $(Build.ArtifactStagingDirectory)/$(projectName)_$(Build.BuildNumber)'
- task: CmdLine@2
name: install_oras
displayName: Download ORAS bin
inputs:
script: |
VERSION="1.2.3"
curl -LO "https://github.com/oras-project/oras/releases/download/v${VERSION}/oras_${VERSION}_linux_amd64.tar.gz"
mkdir -p oras/
tar -zxf oras_${VERSION}_*.tar.gz -C oras/
rm -rf oras_${VERSION}_*.tar.gz
- task: CmdLine@2
name: oras_login
displayName: Login to container registry
inputs:
script: |
./oras/oras login $(REGISTRY_URL) --username $(REGISTRY_USERNAME) --password $(REGISTRY_PASSWORD)
- task: CmdLine@2
name: oras_push
displayName: Push artifacts to container registry
inputs:
script: |
./oras/oras push $(REGISTRY_URL)/$(ARTIFACT_REPOSITORY):$(Build.BuildNumber) $(Build.ArtifactStagingDirectory)/$(projectName)_$(Build.BuildNumber)/:application/vnd.acme.rocket.docs.layer.v1+tar
- stage: Deploy
displayName: Deploy
pool:
vmImage: ubuntu-latest
condition: succeeded()
dependsOn: Build
jobs:
- deployment: Deploy
displayName: Deploy
environment: Production
strategy:
runOnce:
deploy:
steps:
- task: ABCDLiteDeploy@0
inputs:
abcdlite_url: $(ABCD_LITE_URL)
package_ref: $(REGISTRY_URL)/$(ARTIFACT_REPOSITORY):$(Build.BuildNumber)
package_username: $(REGISTRY_USERNAME)
package_password: $(REGISTRY_PASSWORD)
project_id: $(ABCD_LITE_PROJECT_ID)
deployment_token: $(ABCDLITE_DEPLOY_TOKEN)
site_name: $(ABCD_LITE_SITE_NAME)
exclude: |
wwwroot/media
Assumptions made for this pipeline example:
- The solution file (.sln) is in the root of the repository.
- The target C# project is located at
Venus.Presentation/Venus.Presentation.csproj
, relative to the root of the repository. wwwroot/media
is a directory that contains files which must be preserved during deployment.