Microsoft Teams webhook on TFS - tfs

I have discovered Microsoft Teams and I like it.
I am now trying to trigger pullrequest messages from TFS to Microsoft Teams.
I have a Teams Group webhook url that works fine with curl.
But when I test it with TFS (Service Hooks -> Web Hooks) then I only get bad requests.
Do any of you have an idea why that could be?

If you are using VSTS, you could directly use the Connectors in Microsoft Teams to achieve what you need.
Open the Connectors from Teams-General.
Add Visual Studio Team Service
Add related configuration such as blow picture
Create a pull request in related VSTS project, will get a message in Microsoft Teams
If you are using TFS, there is no related add-in for now. Seems you are using Incoming Webhook connector .
For Incoming Webhook, it's only support posts cards. More details about how that card is built, please refer this link: Actionable Messages Reference.
However, for Web Hooks in TFS, the sent JSON representation is not using the "card type". The sample JSON looks like below:
{
"event.type": "git.push",
...
"messsages": {
"text": "...",
"html": "...",
"markdown": "..."
},
"detailedMesssages": {
"text": "...",
"html": "...",
"markdown": "..."
},
"resource": {
"id": "...",
"url": "https://...",
"name": "...",
"field1:": "..."
}
}
So you will get a fail message with bag request(400).

Maybe you figure it out by now cause obviously the question was asked 3 years ago, but I wanted to post my answer in order to help other people in the future.
There actually a way to hook TFS with Microsoft Teams yay!!
From TFS go to Service Hooks --> office 365 instead of (Service Hooks -> Web Hooks) because "Microsoft teams" is part of the suite 365 and as easy as that :).
PS: Of course you need to create a channel on Teams first, then click on the 3 dots --> Connectors --> Incoming Webhooks(configure) --> give your hook a name --> Create. And you're done; just copy the link generated by Teams and past it in TFS when u're asked for it ;)

Related

Parameterize Integration Runtime in linked services of Azure data factory

I have configured CI/CD pipelines for Azure Data Factory. I need to have a separate Integration Runtime for some linked services in Azure data factory for QA environment. When I deploy using the ARM templates of DEV Azure Data Factory from adf_publish branch, I am able to provide values for the parameter for only sql server name, key vault not IR. Is there any way I would be able to provide value of Integration Runtime in the linked service.
Thanks in advance
Please click here to see the screenshot
This can be achieved by following the below link from Microsoft https://learn.microsoft.com/en-us/azure/data-factory/continuous-integration-deployment#use-custom-parameters-with-the-resource-manager-template
A new name can be added under the integration runtime arm template.
Use connectVia property of linkedServices in the arm-template-paramerters-definition.json to change integration runtime from CI/CD
"Microsoft.DataFactory/factories/linkedServices": {
"*": {
"properties": {
"typeProperties": {
"baseUrl": "-::string"
},
"connectVia": {
"*": "="
}
}
}
}
You can go to the 'Manage' of your ADF instance and then go to 'Integration runtimes' to create a new Azure IR for your ADF.
You can create an azure IR based on azure or self hosted.
For more information, please have a look of these document:
https://learn.microsoft.com/en-us/azure/data-factory/concepts-integration-runtime
https://learn.microsoft.com/en-us/azure/data-factory/create-self-hosted-integration-runtime

TFS api build status and create release

Hey all I'm new to the TFS api world so help would be great!
I am looking to gather information on my projects from the tfs version 15.112.26307.0 (2017) server.
My TFS web URL that lists ALL my projects is : http://tfsserv001:8080/tfs/prog/_projects
My TFS test app is this: http://tfsserv001:8080/tfs/prog/---2017
I am looking to get the build status from the Build & Release > Builds tab via API:
And after its succeeded I would then like it to create a release:
Are both above possible by using the TFS api?
There is related Rest API to get build result- include the status info
"result": "succeeded",
You could also use Rest API to create(trigger) a release based on some info such as build ID.
For more details you could take a look at this blog shows how to use rest api in powershell:
Moreover, Daniel is right. You could check the Continuous deployment(create release and deploy whenever a build completes) when you create a new release definition or select in triggers of the release definition. TFS server will handle this automatically, without the need of user intervention.
Update
A example when you open a build result in the web portal just as:
In the entire url there will include a buildID such as buildID=49. So according to above screenshot, you should use
Get http://xxx:8080/tfs/DefaultCollection/ScrumMttApple/_apis/build/builds/49/?api-version=2.0
Then will get below JSON result:
"id": 49,
"buildNumber": "20170525.5",
"status": "completed",
"result": "succeeded",
"queueTime": "2017-05-25T19:17:39.6545026Z",
"startTime": "2017-05-25T19:17:42.2482602Z",
"finishTime": "2017-05-25T19:25:15.6808731Z",
"url": "http://win-kev0061habi:8080/tfs/DefaultCollection/bdd4809b-e6dd-4cb8-8e60-762373b20cdc/_apis/build/Builds/49",
"definition": {
"path": "\\",
"type": "build",
"revision": 5,
"id": 14,
"name": "OrdertTest",
.....

Does VSTS or TFS build process support custom triggers for build?

I don't see any options to customize triggers withing Build Definition except for source control change. I expected to be able to have some sort of script which can be run periodically to verify if new content is posted on HTTP or something more customizable then just source control change. Is it in fact missing or I misunderstood how build is being triggered.
You can use the REST API to trigger a build however you want from an external process.
The built-in triggers (on source control change or on a schedule) are the only way to do it natively.
Here's an example of using the REST API:
POST https://{instance}/DefaultCollection/{project}/_apis/build/builds?api-version=2.0
with the body:
{
"definition": {
"id": 25
},
"sourceBranch": "refs/heads/master",
"parameters": "{\"system.debug\":\"true\",\"BuildConfiguration\":\"debug\",\"BuildPlatform\":\"x64\"}"
}

Trigger TFS Release Management with Artifact Version Number

I am excited to see TFS Update 2 available for on premise and including the Release Management Feature part of the web experience. We have been waiting for this.
I need some help on how best to trigger the release.
A release can be triggered in 3 ways:
Continuous Deployment Trigger based on linking to TFS Build Definition
Manually
REST API
This is great but I don't think it fits what I would expect. I need help in a technical solve or in how I think about the problem.
My Thinking:
I believe the Build should create an artifact and put the artifact in a Drop location to be released now or a year from now. (need to rebuild or add a server later)
I feel the continuous deployment trigger breaks down as it depends on the artifact being in the TFS Build and the TFS Build will be deleted depending on your settings.
Possible Solution:
I believe the solution I need is to create a draft release using the REST Api and then pass in the path to the artifact in the drop location. In my case I would simply provide a version number and build the path inside the release.
Problem:
At this point the REST api is not documented.
I appreciate your thoughts on my thinking. It could be that I'm thinking about the problem in the wrong way.
Also, If anyone knows how to create a release using the REST api that would likely get me to where I need to be.
I see the REST api is to be documented at the following spot but is is not yet. I really want to get going, I have over 100 apps to deploy.
https://msdn.microsoft.com/en-us/library/vs/alm/release/managing-releases/create-release#CreateareleasebyusingtheRESTAPI
We also use TFS 2015 update 2 on-prem and use PowerShell to interface with TFS REST API.
As stated in comments on this thread the REST API documentation is live and to create a release refer to the following link: https://www.visualstudio.com/en-us/docs/integrate/api/rm/releases#create-a-release
To answer your question: - to create a release using a PowerShell script try the following:
$filePath = "C:\PATH_TO_JSON"
$username = 'DOMAIN\USRNAME'
$password = 'PASSWORD'
$body = Get-Content $filePath
$resource = "http://TFS_URL/_apis/release/releases`?api-version=2.2-preview.1"
$cred = New-Object System.Management.Automation.PSCredential($username, (ConvertTo-SecureString -String $password -AsPlainText -Force))
Invoke-RestMethod -Method Post -Uri "$resource" -Credential $cred -ContentType "application/json" -Body $body
The $filePath variable should point to a file containing the following JSON markup. Be sure to alter the variables within the example JSON to fit your on-prem Release Definition:
{
"definitionId": 12,
"description": "M 98 release",
"artifacts": [
{
"alias": "Fabrikam.CI",
"instanceReference": {
"id": "90"
}
}
]
}
You could also use JavaScript to interface with TFS REST API. See the post by #Elmar here: TFS 2015 REST API Authentication
The Release Management API docs for VSTS are live here. Most of the APIs should work for TFS 2015.2 also.
For creating a new release, refer to my earlier answer for the same.
You can retain a build indefinitely so it will always be available when you need it.
ReleaseManagement REST API got public at
https://www.visualstudio.com/integrate/api/rm/releases#Createarelease. Please have a look. While creating the release pass three things in the artifact :- alias, instanceReference (name and Id).

Change TFS Alert Email Subject Line

We are running TFS Visual Studio online. Is there a way to configure the email subject line of alert emails to be more user friendly/Readable
No. This is not something you can do with VSOnline. On premise TFS has some templates on the App Server(s) IIRC that you can edit.
I can't see the VSO team adding customisation, but you could always log something on UserVoice and see what happens.
You could consider using the Service Hooks to push notifications to another service that could then create the e-mails. I've not tried this so I don't know how scalable it will be.

Resources