Azure Pipelines Publish Artifact Output Location (.artifactignore issue) - azure

I have read here: https://www.jfe.cloud/control-pipeline-artifacts-with-artifactignore-file/
that I have to copy my .artifactignore to the location where my artifact will be saved.
However, currently my Publish Artifact task isn't allowing me to set a location. It just says Azure Pipelines. What is the path for this Azure Pipelines?
I cannot use set a location as my agent is running Linux..
This is my current yaml for my Azure Pipelines
steps:
- task: CopyFiles#2
displayName: 'Copy .artifactignore'
inputs:
Contents: '**/.artifactignore'
TargetFolder: '$(Pipeline.Workspace)'
OverWrite: true
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact: sdr_core'
inputs:
PathtoPublish: '$(Agent.WorkFolder)'
ArtifactName: 'sdr_core'
EDIT:
Attached the PublishBuildArtifact screenshot. I cannot select a publish location:

Related

Add .lic file to Azure pipeline during the build

I have an ASP.Net MVC application that runs on an Azure server. It has a module that needs a licence file (.lic) to live in a particular solution folder. I'm not allowed to keep the licence file in the dev environment (locally) for development purposes and just to add and paste that in the specific folder during the build process on Azure.
I found two ways to accomplish that:
Store the content of licence.lic in the Azure key vault and use that like
- task: AzureKeyVault#2
inputs:
azureSubscription: 'my resource group'
KeyVaultName: 'kv-mykeyvault'
SecretsFilter: 'field1--Licensing--Keys--myModule'
RunAsPreJob: false
- task: CmdLine#2
displayName: 'Generate licence.lic'
inputs:
script: 'echo $(field1--Licensing--Keys--myModule) > licence.lic'
- task: CopyFiles#2
displayName: 'Copy licence.lic'
inputs:
Contents: licence.lic
targetFolder: '$(Build.ArtifactStagingDirectory)/path/to/directory/'
or
Simply upload the licence file in the azure → Libraries → Secure Files, download the file and copy that in the proper directory (/path/to/directory) as
- task: DownloadSecureFile#1
name: licence
displayName: 'Download licence.lic'
inputs:
secureFile: 'licence.lic'
- task: CopyFiles#2
displayName: 'Copy licence.lic'
inputs:
sourceFolder: $(Agent.TempDirectory)
contents: licence.lic
targetFolder: '$(Build.ArtifactStagingDirectory)/path/to/directory/'
Is there any significant difference(s) between these two options rather than the first one running 3 tasks and the second option running 2 tasks? If yes, which one is more preferred?

Pipeline to deploy Net Core 3.1 webapp project and Azure Function App project

In my current solution, I have two projects: A Net Core 3.1 MVC project and an Azure Function App project. Both are hosted in Azure, but in different resources (Webapp in an AppService, and the Function App project has its own Function App resource.
-SolutionName
|_ WebApp Project
|_ WebApp.AzureFunction project
In my current Azure DevOps pipeline, I have defined a build and deploy for the webapp only. How can I add a step that will take only the Azure Function App and deploys it to its respective resource?
EDIT: Based on the answer below, I have edited the yaml. The pipeline succeeds, but the zip for the azure function is empty.
My current yaml file looks like this:
# vm-image, variables, building of webapp removed for brevity.
steps:
- task: DotNetCoreCLI#2
displayName: 'Build Project Azure Function: WebApplicationTest.AzFunction'
inputs:
projects: 'WebApplicationTest.AzFunction.PipelineTest/*.csproj'
arguments: '--output $(System.DefaultWorkingDirectory)/publish_output --configuration Release'
zipAfterPublish: false
- task: ArchiveFiles#2
displayName: 'Archive Azure Function'
inputs:
rootFolderDirectory: '$(System.DefaultWorkingDirectory)/publish_output/'
includeRootFolder: false
ArchiveFile: '$(Build.ArtifactStagingDirectory)/functions/azfunction.zip'
replaceExistingArchive: true
- task: PublishBuildArtifacts#1
displayName: 'Publish Azure Function: WebApplicationTest.AzFunction.PipelineTest'
inputs:
pathtoPublish: '$(Build.ArtifactStagingDirectory)/functions'
ArtifactName: 'functions'
#Deploy different artifact to different resources
# Deploy webapp step removed for brevity.
- task: AzureFunctionApp#1
displayName: Deploy to Azure Function
inputs:
azureSubscription: $(azureSubscription)
appType: functionApp
appName: 'WebApplicationTest-AzFunction-PipelineTest'
package: '$(Pipeline.Workspace)/**/azfunction.zip'
I think it needs another step and then take the Azure Function App project from the $(Build.ArtifactStagingDirectory) package, and deploy it to my Function App resource. What is the best way to do this?
How can I add a step that will take only the Azure Function App and deploys it to its respective resource?
We could build and generate different artifacts for those two projects.
We can specify the full path of the project to be built and generate artifacts with different names for deployment to the perspective resource.
For example, I added comments to the code to help understand my ideals:
- task: DotNetCoreCLI#2
inputs:
command: 'restore'
#build the Web App, MVC project, and generate the artifact MVC.zip under the path $(Build.ArtifactStagingDirectory)/MVC
- task: DotNetCoreCLI#2
displayName: 'dotnet publish for MVC'
inputs:
command: 'publish'
publishWebProjects: false
projects: 'MVC/MVC/*.csproj'
arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)/MVC'
- task: PublishBuildArtifacts#1
inputs:
pathtoPublish: '$(Build.ArtifactStagingDirectory)/MVC'
artifactName: 'MVC'
#build the Azure function App, AzureFunctionApp project, and generate the artifact function.zip under the path $(Build.ArtifactStagingDirectory)/function
- task: DotNetCoreCLI#2
displayName: 'Build project for azure function'
inputs:
projects: MVC/AzureFunctionApp/AzureFunctionApp.csproj
arguments: '--output publish_output --configuration Release'
- task: ArchiveFiles#2
displayName: 'Archive files'
inputs:
rootFolderOrFile: 'publish_output/'
includeRootFolder: false
archiveFile: '$(Build.ArtifactStagingDirectory)/function/function.zip'
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact: Function'
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)/function'
ArtifactName: Function
#Deploy different artifact to different resources
- task: AzureRmWebAppDeployment#4
inputs:
ConnectionType: 'AzureRM'
azureSubscription: 'Subscription Name'
appType: 'webApp'
WebAppName: 'WebApp Name'
package: '$(Build.ArtifactStagingDirectory)/**/MVC.zip'
enableCustomDeployment: true
DeploymentType: 'webDeploy'
- task: AzureFunctionApp#1
displayName: Azure Function App Deploy
inputs:
azureSubscription: $(azureSubscription)
appType: functionApp
appName: $(appName)
package: $(System.ArtifactsDirectory)/**/function.zip
The test result:

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.

Azure ARM template deployment for a .NET application

I'm trying to deploy a .NET application using an Azure DevOps pipeline by making use of an ARM template and storing the template in an Azure git repository.
##################yml file for the pipeline build####################
- task: DotNetCoreCLI#2
inputs:
command: 'build'
projects: '**\*.csproj'
arguments: '-c Release'
- task: DotNetCoreCLI#2
inputs:
command: 'publish'
publishWebProjects: true
arguments: '-o $(Build.ArtifactStagingDirectory)/web'
- task: CopyFiles#2
inputs:
sourceFolder: 'appdeploy/'
TargetFolder: '$(Build.ArtifactStagingDirectory)/appdeploy'
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
I am getting an error in the build step of the pipeline saying:
DotNetCoreCLI: If you're using Publish command with -o or --Output argument, you will see that the output folder is now being created at root directory rather than Project File's directory.
##[error]Project file(s) matching the specified pattern were not found.
According to the error message , this issue exists in the “build” step.
You need to define in the build task which .csproj files you want to build.
In your case, the definition path projects: '**\*.csproj' has some issues.
You could use the projects: '**/*.csproj’ to replace it.
Note: The cause of this issue is the backslash.
Hope this helps.

Grab files from Azure DevOps Release Pipeline

I'm trying to do something I thought was super simple... I want to grab generated files (not built) and copy them to an Azure Blob storage
In my Build the last step of my azure-pipeline.yml look like this:
- task: CopyFiles#2
displayName: 'Copy generated content'
inputs:
SourceFolder: '$(Build.SourcesDirectory)/output'
contents: '**\*'
targetFolder: $(System.DefaultWorkingDirectory)/$(Release.PrimaryArtifactSourceAlias)/drop
cleanTargetFolder: true
Then, in the Release I have an Azure CLI step with the inline following code:
az storage blob upload-batch -s "$(System.DefaultWorkingDirectory)/$(Release.PrimaryArtifactSourceAlias)" -d '$web' --account-name frankdemo--account-key '_MYKEY_'
I try different combinations of paths, but nothing works...
Q: What should I put as targetFolder in my build and "-s" in my release?
You will need to add step so it will publish artifacts
steps:
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact: Server'
inputs:
PathtoPublish: '$(build.artifactstagingdirectory)'
ArtifactName: Server
Then in your release you can use "Azure File Copy" to copy from your release to blob storatge

Resources