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",
.....
Related
I have implemented Electron AutoUpdater with PRIVATE GitHub Repository as provider to publish electron application. Now, i can publish it using GitHub repository but Whenever AutoUpdater tries to download the updates from GitHub repository, Everytime it prompts with response code 404 Not found.. I have tried passing token in setFeedURL method and also set it in GH_TOKEN but seems like that does not work either.
autoUpdater.setFeedURL({ provider: 'github'
, owner: 'owner'
, repo: 'repo-name'
, token: 'token'
, private: true });
So, Is there any way to get it working with PRIVATE GitHub Repository ?
Are you using electron auto-updater module? from the API documentation, I can see that they don't support.
On the other hand, if you are using electron-updater module, make sure that you are following the recommended release workflow, and you should not use setFeedURL check the note here
Updated:
If you are using electron-updater and you are publishing to a private repository, you will need to make sure that your token will be available within the app-update.yml file, that's why many say it's not recommended, if the token is not set in your app-update.yml file you will get 404.
For electron-updater to auto add your token to the app-update.yml file the token should be set within the publish section like the following:
"publish": [
{
"provider": "github",
"private": true,
"owner": "<github_owner>",
"repo": "<repo_name>",
"token": "<your github token>"
}
],
This will produce a app-update.yml file like the following:
owner: <github_owner>
repo: <repo_name>
provider: github
private: true
token: <your github token>
updaterCacheDirName: electron-updater-private-updater
Check this small video
Here is my code https://github.com/linuxjuggler/electron-auto-update-example check the electron-builder.json file.
Update 2
Based on the note mentioned in the Quick Setup Guide section, you should never call setFeedURL.
Auto-Update - you can see that private github repos works only for very special cases, and they are recommending to have a separate release-only repository to distribute releases so source is locked down, and you can distribute to controlled machines. It is a useful feature since no server is required, but special use case. Also, you can make this work with s3 bucket or some other upgrade servers.
I found this AutoUpdater Git Repo very helpful and my code is working now. Only change I needed to make is in github yml setting, add a token=<PersonalAccessToken> from github.
You can get Github personal token from Github > Settings > Developer Settings > Personal access tokens > Generate New Token
If anyone is still having this problem (I was stuck for weeks), I created a package to help with this. electron-github-autoupdater
It's pretty much an exact clone of Electron's autoUpdate API that accepts a config object for your private/enterprise github repo configuration and access token. It should just work.
I have been removing unused releases in TFS 2017, due some of them were created automatically and never used. but this task is monkey job. I would like to perform a bulk deletion, or create an script to delete them.
So far, I was checking the REST API but there is no option to abandon or to delete the releases.
Any other suggestion?
Based on my test, you can use the REST API to abandon or delete the release.
Abandoning an active release: (Mentioned in the official document)
PATCH http://server:8080/tfs/DefaultCollection/LCTFVCScrum/_apis/Release/releases/10?api-version=3.1-preview
{
"status": "abandoned",
"manualEnvironments": null,
"comment": "Abandon the release"
}
Delete the release: (Not mentioned in the official document, tracked with the Fiddler tool )
DELETE http://win-server:8080/tfs/DefaultCollection/LCTFVCScrum/_apis/Release/releases/9?api-version=3.1-preview
Both of them work well.
So, you can get the release list first using REST API (to get the release IDs), then create a script to delete the releases with the Release IDs which you want to be deleted.
Get release list:
GET http://server:8080/tfs/DefaultCollection/LCTFVCScrum/_apis/Release/releases
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\"}"
}
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 ;)
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).