We are writing plugin for TFS that expects to receive BuildStarted and BuildCompleted Events.
We found that BuildCompletedEvent can be received via WebHooks.
But BuildStartedEvent is not possible to receive via WebHooks .
Does exist any other way to receive BuildStarted event in TFS 2018?
There is no hook for BuildStartedEvent (Azure DevOps Services service hooks events).
You may use the workaround:
Add as first step inline powershell task (PowerShell task) and send information about your started build (Invoke-WebRequest, POST with parameters) to your service.
OR
Create .net app to send a web request (How to make HTTP POST web request) to your service. Then add first step with command line (Command Line task) to run your custom app.
Related
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.
I have a Jenkins job that will invoke SonarQube analysis on code pulled from a Bitbucket repository whenever there is any changes on the Bitbucket repository. At the moment, I was able to use the Confluence Publisher plugin to publish the URL of the build job to Confluence as a comment.
I was wondering if there is any way I could use Jenkins to screenshot the SonarQube analysis report (like in SonarQube web UI) and publish it directly to Confluence? (So that the user does not need to use the URL to go to the specific Jenkins build job, and then get the SonarQube analysis report URL, and navigate to the page to view the report)
Thank you.
Instead of using a screenshot, you can send a curl request from Jenkins to SonarQube REST API (5.3 and above) to get the project status from the quality gate after the code has been uploaded and analysed. The endpoint you'd likely want to use is: /api/qualitygates/project_status?prjectKey=<projectKey>&branch=<branch>
According to the web API docs:
Get the quality gate status of a project or a Compute Engine task.
Either 'analysisId', 'projectId' or 'projectKey' must be provided
The different statuses returned are: OK, WARN, ERROR, NONE. The NONE status is returned when there is no quality gate associated with the analysis.
Returns an HTTP code 404 if the analysis associated with the task is not found or does not exist.
Requires one of the following permissions:
'Administer System'
'Administer' rights on the specified project
'Browse' on the specified project
Once you have these results available, you can create a Jenkins user in Confluence and have Jenkins send a POST request to create a page or a comment with the results obtained.
I'm trying to do a pretty simple thing I believe - trigger a Jenkins job from a slash command in slack. I want to type /dump in slack and that should trigger particular jenkins job. I'm using Slack Slash command to achieve this and the setup is very simple - type command, type URL, select POST/GET method.
I tried two methods - first was to use Build Authorization Token Root Plugin following this tutorial - in this case I configured Slack slash command to make GET request on the URL: http://jenkins_url:8080/job/db-dump-setup/build?token=MY_TOKEN - If I put the URL to my browser, the job gets triggered, if I run the /dump command, slack responds with:
slackbot [3:41 PM]
Darn - that slash command didn't work (error message: `403_client_error`). Manage the command at text.
The second approach I tried was following this tutorial. In this case I created new user in Jenkins and got API token. When running this command from my terminal: curl -X POST http://USER:TOKEN#slack_url:8080/job/db-dump-setup/build, the job gets again triggered, however when configuring the Slack slash command with the same URL and making POST request, I get the same error: 403_client_error
I tried to google this specific error but didn't find anything useful, also there are no more details for the error or any logs which could help me to troubleshoot this further.
Anyone run into something similar and knows how could I get this resolved?
I was able to resolve this so answering my own question in a case someone else runs into this. In order to make the first case work (Using the GET request), I had to enable the "Allow anonymous read access" in Jenkins, in Manage Jenkins -> Configure Global Security as per the screenshot below.
You should not need to enable anonymous access.Your jenkins requires authentication. Update your url like http://user:auth-token#jenkins-host:port.Auth token can be generated at the following URL JENKINS_HOST/me/configure
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).
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)