How to take code backup in TFS 2015 during Release Management/Pipeline - powershell

I've done Build for my code in TFS 2015. Now i'm configuring CD, my tasks would be
Take Backup of existing release code
Deploy build artifact to my server
Rollback task if deployment fails
I'm struck with Task 1 : Take backup of exiting release code.
I would prefer using PowerShell task as suggested over here, as my my release server path differs with different an ID {mulitple paths with multiple Id's]

How to take code backup in TFS 2015 during Release Management/Pipeline
Indeed, Backing up existing release code on the server is really a tricky issue, if your release server path differs with different an ID. It seems we have to create several task to back up release code from different release server path or we have to write the scripts(PS, Batch) to back up those release code.
To resolve this question, I would like provide a workaround, you can check if it works for you. The tasks would be:
Deploy build artifact to the server.
Use Copy task to back up the build artifact to the local folder of the TFS server machine with condition Only when all previous tasks have succeeded.
Deploy backup artifact to the server with condition Only when all previous tasks failed (Also check the option Clear Target Folder under the Advanced tab).
Some explanations for tasks 2 and task 3:
Task2: This steps is use to back up the release code of the last successful deployment, and save it to the local folder on the server.
Task3: This steps is used to deploy the back up the release code to overwrite the release code that failed to deploy before, if the previous deployment task failed.
Hope this helps.

Related

Where are the artifacts after having built, to be used by release?

I'm new to Aure DevOps. Trying to create build and release pipelines there's one thing I don't understand:
Commonly, every kind of build finally results in some output, called artifacts.
With Azure DevOps it seems like there is always a final copy or publish task necessary to copy the created artifact from A to B, so the release task may then access the compiled artifacts.
Why aren't these artifacts plain accessible to a release pipeline right from the location where they have been built? Why don't the build tasks automatically set a variable pointing to the right folder, so the release pipeline may access the files right from there?
Or is this already happening and I'm just missing something from the tutorials I watched?
There are so many reasons.
Two easy ones:
There is no guarantee that the agent's working folder still contains the files. Agents are reused from build to build and release to release, and a given build or release will always use the same working folder. The working folder is cleaned up between builds.
Releases may run on different agents. On different machines. In different domains. Or any combination. There's no guarantee that the agent where the build ran is accessible by the agent where the release is running. Publishing the artifact allows a guarantee: As long as the machine the release is running on has the ability to talk to Azure DevOps (which is a requirement for the agent to function in the first place), it can get the artifacts it needs.
Why aren't these artifacts plain accessible to a release pipeline
right from the location where they have been built?
Agree with Daniel.
The main reason for me is because we can't hold the hosted agent all the time. Since MS wants to protect resources efficiently, it is not occupied for a long time.
When we queue a build, MS will assign us a brand new clean agent to execute our task, and after the build is complete, the MS will reclaim the agent assigned to our build and restore the agent to its initial state in preparation for accepting the assignment of the next task.
So, we could not keep hold the hosted agent to use it in next release pipeline. We have to store the artifacts in the cloud/server, then we could download it in the release pipeline. Otherwise, we could not get the artifact we need from an agent that has been restored.
Besides, MS is randomly assigned to the agent, and we cannot guarantee that the same agent will be allocated and built during the release pipeline.
That is the main reason why we need to copy or publish the artifacts.
If you do not want to copy or publish the artifacts, you could setup your own private agent, and do not clean the agent before you execute the release pipeline.
Update:
why is the user, well, bothered to find a place for the artifacts
manually? I would have expected every build pipeline to come with a
personal space to store the latest build artifacts. A space where
Azure DevOps automatically copies the build artifacts to. To me it
looks like things have to be manually copied from A to B and then
later from B to C.
That because not all output is needed, for example, the test project, what we need is test result/Code coverage for the test project, not the output for the solution. In this case, we do not need to copy the output to the artifacts. On the other hand, we need to copy some special files to artfacts, then automatically copy the build artifacts will not meet your requirements.
That is also the reason why we provide the task to copy files to artifacts, so that we could customize our personality needs.
Of course, if you think that manual copying is superfluous, you can use the MSBuild parameter /p:output=$(build.artifactstagingdirectory) to set the output directly to artifacts.
If I need to copy things from A to B in the Build pipeline, then what
should keep me from copying it to C right away? Then a separate
Release pipeline would be, well, rather optional, if not redundant.
If you are in the build pipeline, there is another task Download build artifacts, which could download the build artifacts.
if you are in the release pipeline, you just need select the build artifacts as source, release pipeline will download that artifact automatically:
Check this document for some more details.
Hope this helps.

Automated build pipeline Salesforce Azure DevOps

I am trying an automated build process in Azure DevOps for Salesforce. whenever a change is pushed to the repository, my build is triggered and it is working fine and pushing the changes to the related sandbox. Here is the proof for the same
Success Build Process.
The configuration of the build is Build configuration.
The build is working fine as expected. I now want to create a release which will push this change to a different environment, and I don't want this to be automated, hence the option of creating the release. The build path to the ant file in my release is exactly as it should be but I am getting this error. Release Error.
The release configuration is Release configuration
My Repository folder structure is: Folder structure. and my build.xml is within the deploy folder.
I don't know what I am doing wrong but the release is always failing and giving me the error which says:
Error: Not found antBuildFile: D:\a\r1\a\deploy\build.xml
Not found antBuildFile: D:\a\r1\a\deploy\build.xml
Based on the first image (Success Build Process), seems that you already have deployed your changes on that sandbox. Working with metadata deployment in Salesforce is different from java and .net, keep in mind that you already have the "executables", all those XML are already the code that you will change on the environment.
The second point is that on release you are in another agent, Buil and Release pipelines runs have their own lifecycle, so the code existing at the Build pipeline is not available until you send it on "drop" artifact, see Publish Build Artifacts task documentation. So that use copy task to put build.xml on publish folder, then you'll be able to use it on Release pipeline.
When you are executing ant go the /deploy folder and execute your command or check for your ant version using ant -version command.

Copying files and deploying to Azure without building using Visual Studio Team Services

I'm attempting to deploy a web site to Azure using VSTS. Basically, I commit code to the GIT repo and have it setup to run CI, so it begins building as soon as I commit. However, once it hits the release section, it never copies the code to the Azure web app, rather, it gives me this line:
Info: Updating file ({projectname}\error.txt).
It doesn't copy the files I changed, but rather always just copies this file. I checked and there is indeed an error.txt file in my website directory in Azure, but it is always blank.
This build/deploy process isn't "standard" because the build step only downloads from source code, it doesn't build, because the website isn't a "web application", but rather just a "web site", meaning it doesn't need to be built.
So my build step is as follows:
Get Sources
Run on Agent - this step is empty
so the idea is that it just downloads everything from source control, that's it.
Then, my release step is as follows:
Artefacts are from build step above
deploy to environment 1 (dev)
Azure app service deploy, using "package or folder" as $(System.DefaultWorkingDirectory)/
Any idea what I might be doing wrong here?
So I actually figured this out and will leave this here in case anyone else needs it.
I admit I'm pretty new to the Azure/VSTS world, so maybe someone else is making my mistake as well.
If you don't need to "build" your project, then don't. I resolved it by simply skipping the build step altogether. What I was really after was to just download the files from source control and deploy them as-is.
In your release editor, you can specify which "artifact" you want to use to release, and one of the options is source control, which is what I did.
This would be useful for websites like mine where you don't need to build them (mine is DNN/DotNetNuke, so you don't build it before deploying).

Where are TFS 2015 custom build tasks stored?

We use TFS 2015 on premise. Where are the TFS 2015 custom build tasks stored? or how can I download a existing build task?
I know you can download the build tasks from github. But this is not what I am looking for.
They're stored internally in the database. The easiest way to "extract them" is to install a local agent, create a build definition that targets that agent and add the task you want.
Queue the build and the agent will download the task and will store them in a subfolder under the Agent's working directory called "Tasks". Grab the contents from there.
You'll be able to push the task using the tfx build tasks upload command.
If you're downloading tasks from VSTS for installation to a onpremise TFS server, you may need to get access to a specific task version, as the service may be ahead and may have other dependencies which have not been deployed to the TFS server.
Another thing to note is that when downloading a task from VSTS, it may have the preview flag set to true in it's task.json, these tasks can be uploaded, but will be invisible in TFS, before uploading them you should remove the reference to "preview": true from the task.json completely.

Error in running build Definition in VSTS Release Management

I am trying to set up automate release process through Release management using VSTS. I have create one build definition, which triggers on each check-in. I have set up build definition from scratch. The build is failing with following error, not sure where I need to change the work space.
Workspace ws_1_1;Project Collection Build Service (XXXXXXXX) does not reside on this computer. If this computer was recently renamed, the workspace may be updated by running 'tf workspaces /updateComputerName:oldComputerName'.
Any help much appreciated.