How can I exclude a file on Azure Devops in the Deployment? - azure

I apologize for my english, im using a translator.
I need make a deployment on Azure Devops using Continous Deployment but i need exclude a file from the repository (i cant change the repository) then create a deployment in IIS.
I have a WebService file in the repository but i cant ignore or delete it from git. I need to use Azure Devops to ignore it then make a continuous deployment.

Another approch is also to use .artifactsignore. By including this file you can describe which files you want to ignore before building the artifacts package. The tricky part here is correct placing of the file.
Where you save the .artifactignore file depends which path you have specified for the publish pipeline artifact task in your pipeline definition.
Here is good example which helped me to use it:
https://www.jfe.cloud/control-pipeline-artifacts-with-artifactignore-file/

You can use the task Delete Files, as covered below:
# Delete files
# Delete folders, or files matching a pattern
- task: DeleteFiles#1
inputs:
#SourceFolder: # Optional
#Contents: 'myFileShare'
#RemoveSourceFolder: # Optional
The input source folder can be folder $(rootFolder) or $(Build.ArtifactStagingDirectory).
I've had a similar problem and solved it this way. Especially .git or .vsfolder.

Related

How to set bin directory in azure pipelines?

I wrote two azure pipelines. One pipeline build my app as a tool and publishes to a artifact feed.
My second pipeline runs that app from artifact feed. Problem is that my app does not see appsettings.json. When I tried to print current directory I saw that is root repo folder. How to solve this?
What have I tried is to set workingDirectory in task that run's tool as:
$(Build.BinariesDirectory)
$(Agent.BuildDirectory)
etc..
So, when I run tool locally and print current directory files i get all DLL's included. But on azure I get repo root.
Is my approach good or completely wrong?

In Azure templates repository, is there a way to mention repository for a filePath parameter of azure task 'pythonScript'?

I have a template repository for build pipelines say 'azure-templates-repo', I have python task template as mentioned below:
steps:
- task: PythonScript#0
inputs:
scriptSource: 'filepath'
scriptPath: 'python_test.yml' #this is located on repo: 'azure-templates-repo'
My question is on scriptPath, when I use this template in a build pipeline azure-pipeline.yml in a repository my-great-app, azure attempts to find the file in my-great-app instead where it really located azure-templates-repo.
So, Is there a way to mention repository for a filePath parameter of azure task 'pythonScript'?
When you use a template in a pipeline, you are only consuming the .yml template file, not the entire repository that contains the template. So by default no other additional files (besides the template itself) that may exist in the template repository will be available when the primary pipeline is composed.
If you need access to scripts or other files that exist in your template repository you will need to use the checkout task and actually checkout the template repository.
- checkout: git://MyProject/MyTemplateRepo
One thing to be aware of if you go down the path of checking out multiple repositories is that it will cause the structure of your $(Build.SourcesDirectory) to change. In practice this can cause pain as you have to update any tasks that expected your primary repository location to be at the root of $(Build.SourcesDirectory).
That mutation of the $(Build.SourcesDirectory) might not be a big deal for you for new pipelines. It can turn into a pain if you have lots of pipelines that you want to consume a new template in, that require supporting scripts.
One option is to package the supporting template scripts, and publish them to an internal package feed. Then within your template block pull down the required script as a package. I have used this strategy before with templates that needed supporting powerShell scripts. We pipeline those scripts and publish them as a universal packages, then consume them at the template level.

Is there any way to do selective deployment in azure devops?

I have a release pipeline which i use to deploy my resources to other environments. All works fine but the problem is that every time i deploy, all the resources even if no modification is made, are deployed. Is there a way through which i can do selective deployment; i.e. I deploy only those resources which have been modified. Any help would do. Thanks.
That`s a broad question. There is no out-of-box feature to select units to deploy. But you can use variables in the release pipeline:
Define a variable for each resource/unit and set some default value and "Settable at release time" property.
For each resource, define a separate task to deploy and define the custom condition, like: and(succeeded(), eq(variables['Custom.DeployUnit1'], 'YES'))
You can update these variables at the release creation time:
Is there any way to do selective deployment in azure devops?
There is no such out of box way to selective deployment in azure devops.
That because Azure devops release does not support release only changed files since only release changed files not always meaningful and could not archive what the project intend to release (such as the config file only changed in a commit).
But you could create a PowerShell script to compare timestamp for all files:
Create XML file that stores the last upload/publish information of
each files (e.g. file name, date time, changeset/commit version).
Create a PowerShell script file that included the logical to compare
files (get files metadata and compare with that XML file) and copy
updated files to specific folder
Publish the files in that folder
Check the similar thread for some more details.
Besides, if deploying via the deploy.cmd or MSDeploy.exe, you could also use the the -useChecksum WebDeploy flag:
WebDeploy/MSDeploy Quick Tip: Only Deploy Changed Files
Hope this helps.

Azure DevOps - Clean up old releases on on-premise server?

I have a pipeline that deploys code to an IIS folder on an on-premise server. I'm trying to figure out how to best delete old release folders. I'm not seeing anything obvious within DevOps.
Is there a native way of doing this? Or should I roll my own PowerShell script to delete old releases?
Is there a native way of doing this?
Yes, of course there is.
Open your deploy task, go Advanced Deployment Options and then enable the option Remove Additional Files at Destination
Noted: This "delete" operation I mentioned is not mean that clear all the files in local IIS folder. It just delete the files at the destination where there's no corresponding file in the package which is being deployed.
In one word, for some files which same with previous, it will be override as the latest files. And, for any left over files from a previous deployment that are no longer required, they will be deleted.
If you do not trust this option and want to clear the previous files completely, you can also add the Powershell task before IIS manage task and run delete script.
Here is the sample script to delete local files:
Remove-Item -Path "D:\Websites2\*"
You can replace "D:\Websites2\*" as your local website file path.

How to preserve user-uploaded files on WebDeploy in Azure

In the Azure release definition I publish the build artifact to the UAT WebApp using Azure web deploy. However this deletes any previously user-uploaded files (e.g. images).
How can I release to UAT and preserve the user uploaded files?
Do I somehow need to perform the equivalent of extracting the .zip file over the existing files rather than replacing the entire website directory with the contents of the .zip?
You can add the following MSBuild property to your build
/p:SkipExtraFilesOnServer=true
OR add the MSDeploy provider flag:
-enableRule:DoNotDelete
https://dotnetcatch.com/2016/02/01/webdeploymsdeploy-quick-tip-keep-existing-files-during-deployment/
Did you try to use the -skip:Directory option to excluse the directory where the images are uploaded ? See: https://technet.microsoft.com/en-us/library/dd569089(WS.10).aspx

Resources