Azure DevOps Artifacts - azure

I am new to Azure DevOps (Hosted Agent) and am trying to use the Azure Pipelines to build my Java web app using Ant
below is the pipeline file
trigger:
- azure-pipelines
pool:
vmImage: 'ubuntu-latest'
steps:
- task: Ant#1
inputs:
workingDirectory: ''
buildFile: 'ant/build.xml'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.8'
jdkArchitectureOption: 'x64'
publishJUnitResults: true
testResultsFiles: '**/TEST-*.xml'
Project got build successfully but the path of the WAR file is shown as
Building war: /home/vsts/work/1/s/war/Project.war
I am not able find /home/vsts/work/1/s path in Azure DevOps, I tried to search under Artifact but not found, How can I access the /home/vsts/work/1/s so that I can get my WAR file?

You need to use Publish Artifact task in order to be able to obtain the results of your build.
- task: PublishBuildArtifacts#1
inputs:
pathtoPublish: '$(Build.ArtifactStagingDirectory)' # or your build results directory
artifactName: 'drop'
#publishLocation: 'Container' # Options: container, filePath
#targetPath: # Required when publishLocation == FilePath
#parallel: false # Optional
#parallelCount: # Optional
#fileCopyOptions: #Optional

Related

Azure DevOps - Maven Pipeline publish artifacts

I have a scala project, which packages (using maven) perfectly fine locally and also the build pipeline on azure devops works fine. Now I would like to somehow retrieve the produced .jar files in the target folder. Therefore I would like to publish the artifacts. But the .jar files can nowhere be found.
I have the following azure-pipelines.yaml, which copies/publishes the whole folder to the targetFolder, but there is no target folder, only the source code folder is copied. Now my question, how can one publish/access to published artifacts?
trigger:
- azure_devops_pipeline
pool:
vmImage: ubuntu-latest
stages:
- stage: Package
jobs:
- job: Package
steps:
- task: Maven#3
inputs:
mavenPomFile: 'pom.xml'
mavenOptions: '-Xmx3072m'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.8'
jdkArchitectureOption: 'x64'
publishJUnitResults: false
mavenAuthenticateFeed: true
effectivePomSkip: true
goals: 'package'
options: '-Dmaven.test.skip=true -Pscala-2.12 -Pfat-jar'
#sonarQubeRunAnalysis: false
- stage: PublishArtifacts
jobs:
- job: PublishArtifacts
steps:
- task: CopyFiles#2
inputs:
#SourceFolder: '/home/vsts/work/1/s/target/'
Contents: '**'
TargetFolder: '$(build.artifactstagingdirectory)'
CleanTargetFolder: true
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
Eeach job is a seprate machine. SO if you compile and produce files on one job they are not available on next job unless you will publish those files as artifact and download them on another artifact. So if you want to have this working please move them (steps from PublishArtifacts job) to your first job.

How to use Azure DevOps only for the build part ? and the rest of the ci/cd in jenkins

I need this scenario to be accomplish
Jenkins is the main ci/cd tool now we want to use Azure to be our build server but only for the build that is:
Jenkins checkout source
Run some build-in scripts to prepare for build
Send source which previously check out to the build server <-- this is where the AZURE part steps in
Copy the created artifacts back to Jenkins slave
Continue with CD on Jenkins slave
How do i combine the section 3 ?
How do i combine the section 3 ?
As far as I know, you can use Azure Devops self-hosted agent to connect azure devops and Jenkins.
You can refer to the following steps:
Create an Azure Devops Self-hosted agent on the Jenkins server.
Since the Checkout Step is on Jenkins, you could add Copy file task in Azure Devops to copy the Source to the Build Directory.
e.g. Source Repo Path -> $(Build.SourcesDirectory)
After the build step, you can copy the files back to the jenkins slave path.
e.g. Source: $(build.artifactstagingdirectory) -> Target: Slave Path
If your need to copy file to another remote machine, you could try to use Copy files over SSH or Windows Machine File Copy task.
Update:
After you configure the source, you could publish the repo as artifacts in Jenkins Server.
You could use the Jenkins download artifacts task in azure devops to download the artifacts.
Note: The artifacts will be downloaded to $(Build.ArtifactStagingDirectory).
Then you could run the task and publish the build artifacts on Hosted Macos Agent.
To Copy the created artifacts back to Jenkins:
You could add another Agent job and use the self-hosted agent(On linux AWS) to download the artifacts to jenkins server.
Agent Job 1 is running on Hosted MacOs agent. Agent Job 2 is ruuning on Self-hosted agent.
Update2:
Yaml Sample:
stages:
- stage: CopyFile
pool:
name: default
jobs:
- job: testjob
steps:
- task: CopyFiles#2
inputs:
SourceFolder: 'Local Path'
Contents: '**'
TargetFolder: '$(build.artifactstagingdirectory)'
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'Source'
publishLocation: 'Container'
- stage: BuildProject
dependsOn: CopyFile
pool:
vmImage: ubuntu-16.04
jobs:
- job: buildjob
steps:
- task: DownloadBuildArtifacts#0
inputs:
buildType: 'current'
downloadType: 'single'
artifactName: 'Source'
downloadPath: '$(System.ArtifactsDirectory)'
- task: xxx(build task)
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'Artifacts'
publishLocation: 'Container'
- stage: BackToJenkins
dependsOn: BuildProject
pool:
name: default
jobs:
- job: Sendjob
steps:
- task: DownloadBuildArtifacts#0
inputs:
buildType: 'current'
downloadType: 'single'
artifactName: 'Artifacts'
downloadPath: '$(System.ArtifactsDirectory)'
You need to modify the path(Publish Path, Download Path) to meet your needs.

No package found with specified pattern: d:\a\r1\a\**\*.zip<br/>Check if the package mentioned in the task is published as an artifact

I am creating a Build and release pipeline for my .Net core FunctionApp in Azure. I am getting the following error
2020-07-13T07:59:10.6443361Z ##[error]Error: No package found with specified pattern: d:\a\r1\a\**\*.zip<br/>Check if the package mentioned in the task is published as an artifact in the build or a previous stage and downloaded in the current job.
Below is the yaml file of the pipeline
YAML file
# .NET Core Function App to Windows on Azure
# Build a .NET Core function app and deploy it to Azure as a Windows function App.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://learn.microsoft.com/en-us/azure/devops/pipelines/languages/dotnet-core
trigger:
- master
variables:
# Azure Resource Manager connection created during pipeline creation
azureSubscription: 'f296911a-0481-4fed-ba93-a30ef6a5b0f2'
# Function app name
functionAppName: 'srlcustomermanagerapp'
# Agent VM image name
vmImageName: 'vs2017-win2016'
# Working Directory
workingDirectory: '$(System.DefaultWorkingDirectory)/CustomerOrderApi'
stages:
- stage: Build
displayName: Build stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)
steps:
- task: DotNetCoreCLI#2
displayName: Build
inputs:
command: 'build'
projects: |
$(workingDirectory)/*.csproj
arguments: --output $(System.DefaultWorkingDirectory)/publish_output --configuration Release
- task: ArchiveFiles#2
displayName: 'Archive files'
inputs:
rootFolderOrFile: '$(System.DefaultWorkingDirectory)/publish_output'
includeRootFolder: false
archiveType: zip
archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
replaceExistingArchive: true
- publish: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
artifact: drop
- stage: Deploy
displayName: Deploy stage
dependsOn: Build
condition: succeeded()
jobs:
- deployment: Deploy
displayName: Deploy
environment: 'development'
pool:
vmImage: $(vmImageName)
strategy:
runOnce:
deploy:
steps:
- task: AzureFunctionApp#1
displayName: 'Azure functions app deploy'
inputs:
azureSubscription: '$(azureSubscription)'
appType: functionApp
appName: $(functionAppName)
package: '$(Pipeline.Workspace)/drop/$(Build.BuildId).zip'
Release configuration
1.Make sure you've set the Build Pipeline as artifact source, and the build do provide the artifacts:
2.If the issue persists, try to specify the path via Browse Package or folder option:
Then you can check if your release can get the required xx.zip file via this option. Also you can choose to specify the file path using this option.

YAML IIS web deploy deployment group

I am following the tutorial for the IIS web deploy pipeline according to the docs on IIS Web App Deploy task
If you see the parameter list, there does not seems to have any deployment group parameter. Therefore, how do I know / control in which server that the result of the deployment goes?
- task: IISWebAppDeploymentOnMachineGroup#0
inputs:
webSiteName:
virtualApplication: # Optional
package: '$(System.DefaultWorkingDirectory)\**\*.zip'
setParametersFile: # Optional
removeAdditionalFilesFlag: false # Optional
excludeFilesFromAppDataFlag: false # Optional
takeAppOfflineFlag: false # Optional
additionalArguments: # Optional
xmlTransformation: # Optional
xmlVariableSubstitution: # Optional
jSONFiles: # Optional
I want it to deploy to my "Dev" group as per screenshot below. If YAML can't deploy to deployment group, where is the default deployment location (ie, which computer?)
Let's say that I want to deploy to my PC , how do I direct the deployment to go to my localbox and put it under C:/publish ?
As at June 2020 the YAML-based multistage pipeline does not support deployment groups. However, the YAML-based pipeline has an alternative: Environments.
You can create an Environment manually, under Azure Pipelines > Environments. Once you have created the Environment you can add Resources underneath it. At the moment there are only two types of resources supported: Kubernetes and Virtual Machines. The Virtual Machine resource type is a bit misleading: It can be a virtual machine but it can also be an on-prem physical server. If you're deploying to IIS you'll need to create a Virtual Machine resource.
Creating a Virtual Machine resource under an Environment is very much like adding a target to a Deployment Group: When you add the Virtual Machine resource to the Environment it will generate a PowerShell script that you copy to the target server and run there as administrator. Running that script will create a self-hosted agent on the target server and will register that agent as a Resource under the Environment.
This process is almost identical to the process of adding a target to a Deployment Group.
In the YAML file specify the environment under the deployment job. It's not enough to specify the environment by name. You have to also specify the resourceType for the Environment as well as the name.
Here is my YAML for the build and deployment stages:
trigger:
- master
stages:
- stage: 'Build'
displayName: 'Build the web application'
jobs:
- job: 'Build'
displayName: 'Build job'
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild#1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: VSTest#2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
- stage: 'Deploy'
displayName: 'Deploy the web application'
dependsOn: Build
jobs:
- deployment: 'DeployToDev'
displayName: 'Deploy the web application to dev environment'
variables:
Parameters.IISDeploymentType: 'IISWebsite'
Parameters.ActionIISWebsite: 'CreateOrUpdateWebsite'
Parameters.WebsiteName: 'Default Web Site'
Parameters.WebsitePhysicalPath: '%SystemDrive%\inetpub\wwwroot\AspNetDemo'
Parameters.AddBinding: false
Parameters.VirtualPathForApplication: '/AspNetDemo'
Parameters.AppPoolName: ''
Parameters.VirtualApplication: 'AspNetDemo'
Parameters.Package: '$(Pipeline.Workspace)\drop\*.zip'
Parameters.RemoveAdditionalFilesFlag: true
Parameters.TakeAppOfflineFlag: true
Parameters.XmlTransformation: true
Parameters.XmlVariableSubstitution: true
environment:
name: Dev
resourceType: VirtualMachine
strategy:
runOnce:
deploy:
steps:
- download: current
artifact: drop
- task: IISWebAppManagementOnMachineGroup#0
displayName: 'IIS Web App Manage'
inputs:
IISDeploymentType: '$(Parameters.IISDeploymentType)'
ActionIISWebsite: '$(Parameters.ActionIISWebsite)'
WebsiteName: '$(Parameters.WebsiteName)'
WebsitePhysicalPath: '$(Parameters.WebsitePhysicalPath)'
AddBinding: $(Parameters.AddBinding)
ParentWebsiteNameForVD: '$(Parameters.WebsiteName)'
VirtualPathForVD: '$(Parameters.VirtualPathForApplication)'
ParentWebsiteNameForApplication: '$(Parameters.WebsiteName)'
VirtualPathForApplication: '$(Parameters.VirtualPathForApplication)'
AppPoolName: '$(Parameters.AppPoolName)'
- task: IISWebAppDeploymentOnMachineGroup#0
displayName: 'IIS Web App Deploy'
inputs:
WebSiteName: '$(Parameters.WebsiteName)'
VirtualApplication: '$(Parameters.VirtualApplication)'
Package: '$(Parameters.Package)'
RemoveAdditionalFilesFlag: $(Parameters.RemoveAdditionalFilesFlag)
TakeAppOfflineFlag: $(Parameters.TakeAppOfflineFlag)
XmlTransformation: $(Parameters.XmlTransformation)
XmlVariableSubstitution: $(Parameters.XmlVariableSubstitution)
Note the environment information in the deployment stage, specifying the name (Dev) and the resourceType (VirtualMachine):
environment:
name: Dev
resourceType: VirtualMachine
YAML does not support deployment groups. If you want to use deployment groups, you can't use YAML.
Daniell is right, It seems at this moment YAML can't do the release to deployment group The workaround is as below:
add the following code in the build:
task: PublishPipelineArtifact#1
inputs:
targetPath: '$(Pipeline.Workspace)'
publishLocation: 'pipeline'
task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
task: ArchiveFiles#2
inputs:
rootFolderOrFile: '$(Build.BinariesDirectory)'
includeRootFolder: true
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
replaceExistingArchive: true
and then you can go to the release , use iis web deploy, ensure that the correct artefact is used in step 1 and choose your package folder. You should be able to see the artifact that you built.

Deploy ASP.NET Core App Service with Azure DevOps path not found

I have a simple build pipeline that triggers on my git commit and is working great.
Here is the .yaml for that process:
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
variables:
buildConfiguration: 'Release'
steps:
- script: dotnet build --configuration $(buildConfiguration)
- task: ArchiveFiles#2
inputs:
rootFolderOrFile: '$(Build.BinariesDirectory)'
includeRootFolder: true
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
replaceExistingArchive: true
displayName: 'dotnet build $(buildConfiguration)'
Then, I tried to make a Release build, but can't get the zip file across to my deploy step. The steps I follow are:
Publish build artifacts
Download build artifacts
Deploy web service
Here is my setup - Overall release pipeline:
Artifact Stage setup as follow:
Here is my 3 tasks in the Stage 1 (Deploy Stage):
Then the 3 tasks's properties:
And here is the error I'm getting, it is with regard to the artefact publish directory:
You should use dotnet publish to create your binaries. The step will also create a zip file. Then to publish the artefacts, use the PublishBuildArtifacts#1 Task. These steps should all be done within a build, not a release.
Here an example:
steps:
- script: dotnet build --configuration $(buildConfiguration)
displayName: 'dotnet build $(buildConfiguration)'
- task: DotNetCoreCLI#2
inputs:
command: 'publish'
publishWebProjects: false
projects: '**/*.csproj'
arguments: '-o /app'
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '/app'
ArtifactName: 'drop'
publishLocation: 'Container'
Within the release, you don't need the Publish and Download Build Artefact step since the artefacts are already there (_ISOF). After you run the first Build, you can just select the zip file in the "Package or folder" dropdown.

Resources