Does TFS support build in custom web sockets? - tfs

I would like to create a custom build step (plugin) in TFS that will call an API in my external server. I would like to send the result from my server to TFS and notify that the job is finished (can take about 1-2 hours). and only then I would like to proceed to the next build step.
For doing so I need to send my server a "Callback URL" to send the output to (once it's finished). My question is can I open such a small web socket in TFS (from my tfs plugin)? Does TFS have a framework for that?, Or should I attach a custom webservice process in my plugin that will run this web socket.
This plugin will be a step as part of my build system and will be finished only after I get the answer from my server, And I'll need to present this data in another plugin in the summary build page.
Does TFS support \ have some of those capabilities or should I implement the whole thing by myself?

No, it is not supported. You just can invoke TFS API (e.g. REST API) to do something with TFS (e.g. queue/stop build)
You can run a loop at a constant speed to check the result from your external server, if the result is finished, continue to run.
For example (powershell with PowerShell build step):
$inprocess=true
$loopDelayseconds = 300
while($inprocess)
{
# send request to server and check the result
# if result is finished, set inprocess to false, else call Start-Sleep.
Start-Sleep -s $loopDelayseconds
}
Node: you need to change build job timeout value if the task takes too long time (Build definition > General > Build job timeout in minutes).

Related

Is there any mean to be notified at an end of jenkins build run (acknowledgment)

After some unluckily research, I would like to ask here if there is any mean to do a simpe "end of build" acknowledgement apart from emailing on jenkins.
Some tiers application needs to know if a jenkins build run is finished before this one allow another action to be operated.
The restriction is that I do not have any rights to install some http plugin which for instance could allow to notify a webservice (which would have been a fit solution..... ).
Thank you in advance for your help.

Jenkins job submission via curl and get its build number

How to submit the Jenkins job using curl api and get its buid number ?
Note - i tried with the following api, but its not printing any build number.
curl -X POST http://<hostname>:8080/job/<jobname>/build
In general, you can't do this: when you submit (or "trigger") a Jenkins job, this will not necessarily create and start a new build.
When triggering a job, only a request for starting a new build will enter the build queue. Depending on the availability of suitable executors, the actual build will be created (and started) immediately, later, or never at all. Also, multiple queued requests will normally be "squashed", so several submits will result in the same build number.
Bottom line: this can be done (with the constraints mentioned before), but it will require additional (Groovy) scripting for tracking the submit request through the build queue until the build will be started by Jenkins.

Can I automate builds without having acces to P4 server?

I am trying to setup a jenkins server for the very first time. I have synced it to the Perforce server I use, and I have created a workspace for that. Now I would like jenkins to start building everytime a change is submited, I have been researching through the topics here, and I found this link: How to trigger a Jenkins build on a Perforce submit. But it mentions that in order to do that I have to create a script on the P4 server On the Perforce server, it is possible to create triggers or, in other words, scripts to be run on a particular event - for example after a change-commit., I do not know what it means to create a script on the P4 server. Does it mean I need to have physical access to the server? I am just connecting to a remote server. I am kinda lost here...
Ideally, you'd have access to be able to create a trigger. If you can't do that, the next best thing is to create a cron job or scheduled task (depending on your OS) to check to see if there is something new. I've run similar jobs to:
Run p4 sync -n to see if there is anything new
If there is something new, a) sync it and build it (your choice of everything, or you could write something that would test, say, the first changelist for which there is something new, then keep doing so changelist-by-changelist)
If there is already a build in progress, don't run.
My jobs were set to check every five minutes, but I even had a project where once/hour was enough.

Jenkins Remote Trigger, but don't build immediately the remote build, schedule the remote build instead

I have 2 jenkins machines:
JenkinsA and JenkinsB.
I need a trigger in JenkinsA to trigger the execution of a project in JenkinsB. However I don't need to run remote job immediately. I need put it in queue and be able to schedule when it will run.
I also need send parameters from A to B.
Currently I am using the plugin:
https://wiki.jenkins-ci.org/display/JENKINS/Parameterized+Remote+Trigger+Plugin
This plugin allows build remotely and send the parameters, but it does not allow the execution schedule in the job of Jenkins B.
When using the build trigger and triggering the job remotely, you can append &delay=30sec (or any number of seconds) to the end of the build URL. This will allow the job to enter the quiet period and delay the build for the set period of time. the URL will look something like this JENKINS_URL/job/build?token=TOKEN_NAME&delay=30sec **or** /buildWithParameters?token=TOKEN_NAME&delay=30sec

How to call a web service from TFS which intimates automatically on every TFS build event changes

I have a requirement my below,
We have a build release server environment, which has currently linked with the Teamcity Build system and Kb system, etc. That means, in Teamcity, every build event changes (i.e., events like, build started, build finished, build succeed, build failed, build quality changes/pinned, etc.), it notifies/calls the release system web service with build details (the Xml data).
Now, we are trying to move to the TFS 2013 system instead of Teamcity and I am new to the TFS administration things. I have got a task to connect the release server and do the same job like Teamcity. Which means, in TFS system, on every build event changes (like, build started, build finished, build succeed, build failed, build quality changes, etc.), it should call the release system web service with TFS build Xml data so that I can update that in our database. Would you please tell me the method by which I can achieve that?
FYI,
I have tried with TFS alert notification as below. But, seems like it doesn’t allow to call web service from this section. It only allows to mail the details to specific users. Please let me know if I am wrong.
If it can be achievable through XMAL script, would you please provide some test XAML scripts how can I call the web service from this?
Thanks.
There are multiple ways to achieve this.
But if the alert types are sufficient for your needs, then going through the alert mechanism is the simple way.
You will just need to create a simple listener service to be notified of the desired event (you already suspected of a such mechanism) using alert mechanism's SOAP event feature.
Create a simple web service, having a method like below:
public void Notify(string eventXml, string tfsIdentityXml, SubscriptionInfo subscriptionInfo)
{
EventProcessor.Process(eventXml);
}
SubscriptionInfo class is defined in Microsoft.TeamFoundation.Framework.Server, but you can also use the override without it if available.
Then publish and make available this service, for example having the address: http://localhost:101/NotifyCorpService.svc
Then, you should add an alert for each event you want to be notified (or a single one if applicable using conditions together):
Create an Alert
Set Alert's property "Format" to "SOAP"
Set Alert's property "Send To" to "http://localhost:101/NotifyCorpService.svc"
Finally, you can use the "eventXml" and using its contents, call the web service you want in the code behind of the simple web service we created (NotifyCorpService in our example)

Resources