Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access files in VSTS Source Repo at the time of release definition?

I have some 10 files in the VSTS source code repo (Git) I want to access those files at the time of release definition. I have kept my PowerShell scripts in the VSTS source Repo and after the deployment, I need to run those script files.

enter image description here

So I have added power shell task after the deploy in the release definition but not sure how to access those script files and how can I run those? I can publish those script files from VSTS build definition and can use at the release definition time but I don't want to use in that way.

I want my release definition to run independently.

like image 974
PRAVEEN PDBR Avatar asked Nov 30 '17 12:11

PRAVEEN PDBR


People also ask

How to add VSTs solution to TFVC repository?

Add Solution to Source Control. Select the VSTS project and click on OK to add the solution to TFVC repo. In Team Explorer go to Pending Changes and Check-in. Under Related Work Items, you can also add the work item by ID or title to link the changes The ASP.NET project is now under the TFVC version control repository.

What is Microsoft VSTs and how it works?

Click here to navigate to the visual studio website. Hence, Microsoft VSTS is an Application Lifecycle Management (ALM) system which helps the entire project team to capture Requirements, Agile /Traditional Project Planning, Work Item management, Version Control, Build, Deployment, and manual Testing all in a single platform.

What is a release in DevOps?

A release is a collection of artifacts in your DevOps CI/CD processes. An artifact is a deployable component of your application. Azure Pipelines can deploy artifacts that are produced by a wide range of artifact sources , and stored in different types of artifact repositories.

How to add VSTs accounts to a project?

Search all the VSTS accounts created by the team and Add them to the project just created. Save changes once done. All the accounts added are shown and displayed on the dashboard. As in my earlier tutorials, we will start by creating User stories and link Tasks to it.


1 Answers

In your release definition, you can add one or more artefact sources. These sources can include TFVC and Git repositories as well as the output of a Build Definition.

Reference your repository as an artefact

You can have multiple artefact sources, so you can add the Git Repo as a secondary source:

enter image description here

Note: this will not just fetch these scripts, but it will pull the repository again during the release workflow. This can be time-consuming if your repository is large.

You can consider putting them in a TFVC repository, as that allows very specific mapping of required scripts.

Publish your scripts in a separate build definition

The normal approach would be to publish these scripts as an artefact of a Build Definition (doesn't have to be the same build definition as your main Build). That way you only have to sync these scripts and won't need to get the full repository. To be clear, you can have one build definition that contains the contents of your build linked to the Release and have another build definition linked which published just the scripts.

enter image description here

Note: You don't need to publish these scripts every time you want to use them, your release definition can keep referencing the published artefacts from months ago. The script build only needs to run in order to publish the scripts as they change. A CI build with a trigger filter can be used to only republish the scripts when they change.

Leverage a script repository such as PowerShell Gallery, NuGet, Chocolatey

Other options you may want to consider are publishing your scripts to a PowerShell gallery, Chocolatey gallery etc and as part of your release workflow, you can then fetch these scripts through One-Get.

You can use the NuGet task in a build definition or nuget.exe to push these scripts to the VSTS package management feature. And you can use a commanline task or inline powershell task to install the powershell module on the agent.

Use the REST API

This is a more developer centric approach, you can call the REST API of VSTS/TFS to download individual files from a Git repository. The Download Item api allows you to fetch individual files. It wouldn't be hard to create a Build task that uses the Invoke-WebRequest powershell command to download and save the desired files.

Create a custom build task

A final option you could consider is building a custom build/release task. PowerShell scripts can easily be included in a custom build task and they can be installed to the VSTS/TFS account. That way you can re-use your scripts, have a small UI around them if desired without having to reference a repository at all. You would have to update and publish your task every time you change the scripts. Though you could use the REST API to always download the script before invoking it.

like image 73
jessehouwing Avatar answered Oct 01 '22 00:10

jessehouwing