How to use powershell in tfs 2017 - powershell

I am trying understand how to really use PowerShell in TFS. I would like to add a release step to create a work item task, to tell our release management team they require to approve a release.
Our company has many team projects and I want this to be available as a module that can be used by any project. The process I am using to use this is I am adding an artifact for the TFS project that we store our generic item.
It is under $\BuildSupport, for this example, I create a build for my project under $\WEB. I am also creating the release Under $\Web as well. I create my new release definition, I add my Build artifact.
I then add a Team foundation Version Control Artifact to $\BuildSupport Source alias is "BuildSupport".
I then add a environment step called TEST PRODUCTION and add PowerShell task where the script path is: $(System.DefaultWorkingDirectory)/BuildSupport/Main/BuildTools/TFSBuildScripts/CreateWorkItem.ps1
My issue is that when creating a new release it asks every time for me to choose the artifact version based the changeset for BuildSupport.
I don't want to have everyone do this every time is there a better way?

There isn’t the way to queue a new release without specify the version of TFVC artifacts. I submit a user voice here: Default version of artifacts when queue new release.
The workaround is that:
You can create a task group for each team projects, then add this task group to related release definitions. (you need to update the task group if there are updates)
Create or open a release definition
Add PowerShell task and configure it (e.g. Type: Inline Script, Arguments: [necessary arguments], Inline Script: [powershell script] etc…). You also can specify the PowerShell file in the Shared folder (Map BuildSupport to shared folder, then current version is the "default" version when queue release)
Right click this task > Create Task Group
After that you can add this Task Group to other release definitions directly.
Another way is that you can create a build/release task extension, then install it for necessary team project, after that you can add that custom build/release task to build/release definition. For this way, you just need to update the extension if there is the update.

Related

How to deploy to a server without build a projekt

We have an ImageVault website that we do not develop ourselves. But want version management in TFS and be able to publish against tests and production servers.
It does not need to be built because it is already finished.
How should you set up a building when you should not build anything?
Is it possible to set up a pipeline without having a building?
It is possible to set up a pipeline that doesnot build your project. You project is built by the build tasks in the pipeline. You can just disable or exclude the build tasks from your pipeline if you donot want your project be built.
You can also create an empty pipeline without any tasks inside. You can follow below steps to create an empty pipeline.
1,Sign in to your Azure DevOps organization and navigate to your project.
2,In your project, navigate to the Pipelines page. Choose the Pipelines tab and click new pipeline on the top right corner of the page.
3,Walk through the steps of the wizard by first selecting the location of your source code.(You can create a classic UI pipeline by choosing "Use the classic editor to create a pipeline without YAML".)
4,Then choose to start with An Empty Job under Select a template
With above steps, a pipeline without build tasks is created. You can then add some utility tasks like copy file task, publish artifacts task etc. Utility tasks donot do the building work.
You might need to add some utility tasks like publish build artifacts tasks if you want to deploy release pipeline.
Check here to learn more about creating your pipeline

How to move VSTS build and release definitions from one instance to another instance?

We have many VSTS instances,We are trying to consolidate multiple VSTS instances into 1.For that we need to move all the build and release definitions to one particular instance.Please help me out on this.I want the procedure how to proceed on this.I tried from google but not getting any solutions.Please help me out.I am new to VSTS.
The easiest way is to use the REST APIs.
First, make sure both instances have the same build/release task extensions installed.
The process, then, would be:
Retrieve a build definition
Update the build definition to use the appropriate agent queue in the target instance
Import the build definition and note the build definition ID
Repeat for all build definitions
Retrieve a release definition
Update each environment in the release to use the appropriate agent queue in the target instance
Update the artifacts to point to the appropriate, newly-import build definition(s) (using the IDs from the previous step)
Import the release definition
Repeat for all release definitions
You may also have to update approvers or something similar. Basically, it's going to be a trial-and-error process.
You can export the build and export the release.
Export build definition
Export release definition
On your target team project, you can import your exported files.
Import build definition
On the builds hub:
Import release definition
Note that after importing you will need to point your release to the correct artifacts, but this is a small step, just changing the artifact to use the new one.

How do I Copy Task Groups in Visual Studio Online?

Task Groups are a great way to build a library of commonly executed Build and/or Deployment Actions in Visual Studio Online. Does anyone know of a way to make a copy of (or clone) an existing Task group? I don't see that as an option in the UI anywhere.
I think there is no way to do this yet. It's not even possible on TFS On-premise. Though our TFS professional told us, it should come with TFS2017 Update 1.
Only thing you can do, is select all tasks in your task group and create a new TaskGroup with them. Which is basically the same as cloning the task group itself - it only takes you some clicks more.
Or you could export your task group, change its name and Id in the exported Json, and import it.
Currently there isn't the copy Task Group feature in VSTS and TFS.
You can create TaskGroups according to your requirement and manage them from TaskGroups tab, then use them directly in different scenario. Please follow below steps.
Create a Task Group from Build/Release definition
Navigate to Build&Release > Task Groups
Select the Task Group you need to modify, change the Properties/Tasks
Save the Task Group
If you just want to copy the Task Groups, you can install the "Copy Build Steps" extension. it can copy build/release steps from one definition to another, also support copy the Task Group.
After installing the extension, navigate to the Builds hub > All definitions. A new menu item, ‘Copy build steps’ will be available when you click the ‘’…’’ behind the definition.
To Use a task group:
In a build/release definition, choose Add steps/tasks to open in the Task catalog. Select the category you specified for your task group and find the task group (it displays the name and description you specified when you created it), then choose Add - just as you would with any other task.

Need to add reference from one VSTS Build task to another task

I am working on creating custom vsts build task using Hosted agent and powershell script. I just want to add reference of existing task available out of the box in vsts (Publish Build Artifacts). Is there any way to reference this task in our custom task? Or I just have to implement the functionality provided by PublishBuildArtifacts manually?
The way to reference another task us to grab the sources from the Task Repository on GitHub and package them with your own task (in a subfolder). You'll need to copy the inputs from their task.json and merge them into yours if you want to allow other users to configure the fields exactly the same way as the other task is doing.
You can find the task implementations here: https://github.com/Microsoft/vsts-tasks make sure you select the right branch, the master branch is the bleeding edge, and it may contain a version of the tasks that is not fully battle tested or may not be compatible with the latest version of the agent that has been released (or the minimal agent version you are targeting).
Or you can grab the implementation from a build agent's tasks directory.
Remember that for certain functionality, the VSTS Task SDK has built-in methods to upload artefact, which may make your life easier if you decide to implement the functionality on your own.
The team that built the agent has been pretty specific about making sure that tasks are self-contained and need to package their own dependencies or flag a demand. This is to ensure that each task can evolve and change independently.

How to create custom folder from the release folder of Windows Work flow for TFS Build process?

I have used the
/p:GenerateProjectSpecificOutputFolder=True for creating build for each and every project in my solution and now i wanted to customerize the folder structure on my needs. How can we achieve this?
enter image description here
If you are using XAML build, you can customize Binaries folder in TFS Team Build by modifying the build process template. Adding CreateDirectory Activity and FindMatchingFiles activity are necessary, following this blog for more details.
If you use the new build system, that will be much easier to manage artifacts. With task Publish Build Artifacts, you can specify contents in the task, also you can add as many Publish Build Artifacts task as you want to manage artifacts. More details, check http://www.codewrecks.com/blog/index.php/2015/06/30/manage-artifacts-with-tfs-build-vnext/
Alternatively you can extend your build definition with a PowerShell script at different points within the build:
Pre-build
Post-build
Pre-test
Post-test
Note I am using the TfvcTemplate.12.xaml template. This is the build template that comes with TFS 2013.