I have a situation where I need to deploy different stylesheets to different environments (Dev/Test etc).
Is there a way I can edit the publish artefact so I can do a release pipeline for each environment?
So I would have a build pipeline that produces theused.css, dev.css,
test.css
I would have a release pipeline for Dev & Test
The dev pipeline would edit the artefact by deleting theused.css then rename
dev.css to theused.css .. likewise for test
Or is there a better way to do this?
If I would want to rename a file I would probably write a bash/powershell script and execute it as a task in the pipeline.
Bash task
Power Shell Task
Specifically in your case I would copy/rename the dev.css/test.css to theused.css during the deployment step.
I do not know how you deploy but you could either rename the .css before the deployment to an S3 bucket for example or if you deploy on an on premise server copy the file and rename it at the same time.
cp /your/dev.css /your/deployed/path/to/theused.css #copying the file
mv /your/dev.css /your/deployed/path/to/theused.css #move/renaming the file
Meant to add this...
What I ended up doing was the following (with different configs, rather than css, but same idea):
In my app I have configs for Dev, Test & Prod (config.json, config-test.json, config-prod.json)
The first thing the app does is load the config when it runs
I build and deploy to dev
The build folder contains the build files including these config files
I have releases for Test and Prod that do the following:
Task 1: delete the config.json
Task 2: copy the appropriate config file, e.g. config-test in the test release pipeline, and rename it config.json
Task 3: deploy build files to the appropriate environment with the new config
Related
When you set up an azure devops agent on a build machine, it will have a working folder (by default _work) where it will create subfolders for each pipeline that it has to run.
These folders have integer names like "80" or "29". This makes it hard to trouble shoot issues on a given build machine, when you have many pipelines, as you don't know which folder it each pipeline relates to.
Is there a way to figure out the mapping from pipeline > folder number, or to name these folders more explicitly?
Rename the folders is currently not supported in Azure DevOps.
Each pipeline maps a folder in the agent-> _work.
1.You could check the pipeline log to figure out which folder is your pipeline's working folder. (Enable system diagnostics)
2.You could also add a command line task in your pipeline to echo this directory.
echo $(System.DefaultWorkingDirectory)
I would like to keep the solution backup to some folder before releasing the new build in my Azure CI/CD pipeline. And to deploy the solution, I am using my on-premise server. Not sure where to make changes to save existing artifacts to some folder before getting the new release.
This way we can avoid the failure if something goes wrong to current release. We can have the backup to copy the file.
Release Pipeline
I would like to keep the solution backup to some folder before releasing the new build in my Azure CI/CD pipeline.
Based on your requirement, you can use the Copy files task to copy the existing files on the server to the target folder.
Here are the steps:
Step1: you can check the IIS deployment Physical path in IIS web app manage task.
For example: %SystemDrive%\inetpub\wwwroot
Step2: you can add the Copy file task at the top of the Release Pipeline. Then you can set the Physical path and target folder to copy the existing files.
For example:
In this case, when the release pipeline is running, it will backup the existing files first and then it will deploy new files to local server.
On the other hand, since you are using CI/CD pipeline, the related files will be saved in Build artifacts. You just need to change the build artifacts version in Release Pipeline, then you can deploy the previous artifacts again.
I am using IIS Deployment template in Release pipeline to deploy MVC application to VM and it is working fine. But after deploying application, we want to run any ad-hoc sql changes using script files in SQL server using custom task Run SQLCMD Scripts from VSTS market place.
Relese pipeline, scripts are in zip file, Can anyone suggest what we should key-in in "Path to folder containing SQLCMD script files"?
You can try referencing the variable
$(Build.ArtifactStagingDirectory)
In Release Pipeline, the artifacts will be downloaded to the path : $(System.ArtifactsDirectory).
According to your screenshot, I noticed that you are using the "Extract files" task. This task will find the zip files in the $(System.ArtifactsDirectory) and extract it.
The unzipped folder name is set in the "Extract files" task (Destination folder).
So you could try to use the following path:
$(System.ArtifactsDirectory)/Destination folder name
You can also expand this path according to the actual location of the file.
Hope this helps.
We are in process of creating architecture for VSTS CI/CD to deploy our web app to our Azure App Services.
We want to exclude the web.config while deploying it to the Azure server as we are directly modifying the web.config on the different environment.
CI Tasks looks like this:
CI Taks
CD Task:
Deploy Azure App Service
I am aware of other ways of updating the web.config https://learn.microsoft.com/en-us/vsts/build-release/tasks/transforms-variable-substitution, but in our case we want to skip the web.config file.
I couldn’t find the option to skip file in during release in VSTS as mentioned in this thread
How do I exclude the .cs files within an artifact from a vs-team-services CI build?
Is there a way to exclude certain files while building and deploying the release?
Added -skip:objectName=filePath,absolutePath=web\.config in additional arguments. This skips updating the web.config file during deployment.
You can exclude the web.config before publishing artifacts in your build definition: copy the web packages files to a directory (such as $(build.binariesdirectory)), then copy the files exclude web.config to another folder (such as $(Build.ArtifactStagingDirectory)/package), and zip the files under $(Build.ArtifactStagingDirectory)/package. And finally publish the zip file as build artifacts.
Details changes in the build definition as below:
Change the MSbuild arguments as /p:OutDir="$(build.binariesdirectory)\\" in Visual Studio Build task.
Add a Copy Files task after Visual Studio Build task. Settings for this task as below:
Add Archive Files task after Copy Files task. And settings as below:
Change the Publish Artifacts task as below:
Now the build artifacts are exclude web.config file.
Additional arguments
-skip:objectName=filePath,absolutePath=\\Configuration\\AppSettings\\Base.config
you can add
-skip:objectName=filePath,absolutePath='.*\PackageTmp\Web.config$'
in Additional Arguments in "Deploy IIS WebSite/App" deployment VSTS task, this will not deploy your root web.config file.
I have a unique need where I need to perform releases from Team Services using a Release Pipeline and artifacts that have been created in a previous external build. I have the artifacts that were created, dacpacs and websites ect.
I would like to deploy these items using the features in release Pipelines but artifact sources only come from a build or some other version control.
My approach (hack) was to use a build to copy the external files and publish them into the artifact container for the build. I could then use the release pipelines to do my releases. But .. Build copy tasks only seem to work with paths into a repo.
My fall back will be to use the release pipeline and powershell to do the releases with these externally created artifacts. I would sure like to avoid this since there is nice capability in the release pipeline tasks.
This is a compliance requirement my firm has which results in the rather crazy post.
Any help would really be appreciated.
You can use Copy Files task and Publish Build Artifacts task for your build definition.
Copy Files task
Source Folder: you can specify the folder which has your external build artifacts. Such as C:\project\a.
Contents: you can use wildcards to specify which files to copy. Such as **\*.dll, this will copy all *.dll files in C:\project\a and it’s subfilder.
Target Folder: where you want to copy these files. Usually it’s $(build.artifactstagingdirectory).
Publish Build Artifacts task
Path to Publish: set as the same with Target folder in Copy files task. Such as $(build.artifactstagingdirectory).
Note: Copy files task will find the source folder in the machine where the private agent is located.