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?
Related
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:
In my yaml file I have two tasks : CopyFiles and run a Powershell script.
If only the Powershell task is there, then no problem. I runs fine. So the ScriptPath is OK.
But with the CopyFiles task preceding, it isn't able to find the Powershell file anymore (see screenshot).
Anyone has an idea?
jobs:
- job: sync_wiki_repo
displayName: 'Sync wiki'
steps:
- checkout: wiki
- task: CopyFiles#2
displayName: Copy wiki files
inputs:
contents: 'Wiki/Distribution/Client-Welcome-Page/Readme.md'
**targetFolder**: '$(System.DefaultWorkingDirectory)/wiki-staging'
overWrite: true
- checkout: git://something/set-wiki #checkout specific branch
- task: AzurePowerShell#5
displayName: 'Set wiki'
inputs:
azureSubscription: 'mysub'
ScriptType: 'FilePath'
**ScriptPath**: '1.0/scripts/sync-wiki-repo.ps1'
ScriptArguments: '-wikipat $(e2e-pipelines-manage-wiki-secret) -project ${{parameters.project}}'
azurePowerShellVersion: 6.4.0
workingDirectory: '$(System.DefaultWorkingDirectory)'
As this is running on an Ubuntu Linux machines, the names of the folders and files are case sensitive. I doublechecked that. And I added "E2E-Pipelines" to the Scriptpath.
ScriptPath:'E2E-Pipelines/1.0/scripts/sync-wiki-repo.ps1'
Now my powershell file can be found.
It is solved.
I am facing this odd situation. I have the following setup.
React JS app created using create-react-app
Code on GitHub
Azure Web App - Create from the Azure Portal.
Azure DevOps + Pipelines + YAML
I have been doing a bunch of deployments this week and I noticed this situation. Every 1st deployment, always ends up with the following situation inside the wwwroot folder.
But, every subsequent deployment, works just fine.
To reproduce
Create a new app with create-react-app
Put it on GitHub
Link GitHub repository with Azure DevOps Pipelines
Target the Pipeline to deploy to a Azure Web App, which has been created brand new.
The initial deployment, will always fail, with the above image. And, please, remember, Subsequent deployments dont fail.
So, the question is, is there something I can do to prevent this?
I am planning to automate resource creation on Azure, along with automating deployment.
Update 1
as per the comment, including my YAML here. I use this in all of my react JS deployments, which show the same issue as above.
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
- task: NodeTool#0
inputs:
versionSpec: '10.x'
displayName: 'Install Node.js'
- script: |
npm install
npm run build
displayName: 'npm install and build'
- task: CopyFiles#2
inputs:
Contents: 'build/**' # Pull the build directory (React)
TargetFolder: '$(Build.ArtifactStagingDirectory)'
- task: PublishBuildArtifacts#1
inputs:
pathtoPublish: $(Build.ArtifactStagingDirectory) # dist or build files
ArtifactName: 'www' # output artifact named www
- task: ArchiveFiles#2
inputs:
rootFolderOrFile: '$(Build.ArtifactStagingDirectory)/build/'
includeRootFolder: false
- task: AzureWebApp#1
inputs:
azureSubscription: 'ReactJSRecipeAppConnection'
appName: 'ReactJSRecipeAppSep232020'
package: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
FAILED TO INITIALIZE RUN FROM PACKAGE usually means the zip file is corrupted or not deflateable. Please check whether the WEBSITE_RUN_FROM_PACKAGE flag under App Service -> Application settings was set.
In addition, try to use task Azure App Service deploy v4, instead of task Azure Web App v1.
Taking off from the discussion about with #Cece Dong, here is what eventually worked for me.
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
steps:
- task: NodeTool#0
inputs:
versionSpec: '10.x'
displayName: 'Install Node.js'
- script: |
npm install
npm run build
displayName: 'npm install and build'
- task: CopyFiles#2
inputs:
Contents: 'build/**' # Pull the build directory (React)
TargetFolder: '$(Build.ArtifactStagingDirectory)'
- task: PublishBuildArtifacts#1
inputs:
pathtoPublish: $(Build.ArtifactStagingDirectory) # dist or build files
ArtifactName: 'www' # output artifact named www
- task: ArchiveFiles#2
inputs:
rootFolderOrFile: '$(Build.ArtifactStagingDirectory)/build/'
includeRootFolder: false
- task: AzureRMWebAppDeployment#4
inputs:
appType: webApp
azureSubscription: 'RandomStuffReactJSConnection'
WebAppName: 'randomstuffreactjsappsept24'
package: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
The above, I can confirm, no longer requires a second trigger for a proper deployment.
specifically, the usage of 'AzureRMWebAppDeployment#4' is what solved the original issue.
We have an Azure DevOps Pipeline that runs our application as ZIP package https://learn.microsoft.com/en-us/azure/app-service/deploy-run-package
as opposed to ZIP Deploy. So we are not able to SFTP into our Web App and change something. Why does the Pipeline runs our application as ZIP package and how can we change this?
This is the Pipeline:
trigger: none
pool:
vmImage: 'windows-latest'
steps:
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
restoreSolution: 'Solution1.sln'
- task: VSBuild#1
inputs:
solution: '$(agent.builddirectory)\s\Folder\Project.csproj'
msbuildArgs: '/p:OutputPath="$(build.binariesDirectory)\Folder\bin" /p:DeployOnBuild=true /p:DeployDefaultTarget=WebPublish /p:WebPublishMethod=FileSystem /p:SkipInvalidConfigurations=true /p:publishUrl="$(build.artifactStagingDirectory)\ProjectTempFolder"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: CopyFiles#2
inputs:
SourceFolder: '$(build.artifactStagingDirectory)\ProjectTempFolder'
Contents: |
**
TargetFolder: '$(build.ArtifactStagingDirectory)\ProjectArtifacts'
- task: ArchiveFiles#2
inputs:
rootFolderOrFile: '$(build.ArtifactStagingDirectory)\ProjectArtifacts'
includeRootFolder: false
archiveType: 'zip'
archiveFile: '$(build.ArtifactStagingDirectory)\Project.zip'
replaceExistingArchive: true
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(build.ArtifactStagingDirectory)\Project.zip'
- task: AzureRmWebAppDeployment#4
inputs:
ConnectionType: 'AzureRM'
azureSubscription: 'Subscription1'
appType: 'webApp'
WebAppName: 'CoolWebApp777'
packageForLinux: '$(build.ArtifactStagingDirectory)\Project.zip'
Why does the Pipeline runs our application as ZIP package and how can we change this?
It seems you want to disable to run your Web App from a package, AFAIK, the default version in the release pipeline is now set to Version 4. This version has the "Select deployment method" checkbox disabled, which in turn, allows the "Run as Package" feature by default as well. To change this value, go into the "Deploy Azure App Service" task for each environment and expand Additional Deployment Options. You’ll probably want to change it most often to Web Deploy:
Besides, you can turn that off by deleting the WEBSITE_RUN_FROM_ZIP or WEBSITE_RUN_FROM_PACKAGE application setting in the portal.
Note this will clear your web app until the next time you publish.
Hope this helps.
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.