Jenkins Workflow Build Information - groovy

How do you access current, and related, build information from within a Jenkins workflow groovy script?
I can see things like currentBuild.result and currentBuild.previousBuild being documented, but I can't see how I can access, for example:
The URL of the current build job.
The URL of build jobs that this workflow triggered.
The console output of a particular failed build job, etc.
Thanks for any pointers.

currentBuild.rawBuild will give you the non cached hudson.model.Run object, see hudson.model.Run
from there, to access i.e. the build log:
def buildLog = currentBuild.rawBuild.log
currentBuild.rawBuild is also of type hudson.model.AbstractBuild which can give you other details like changeset, actions

Related

How to get current workflow properties from node.js?

I have several GitHub actions created with workflow *.yml files. They run automated tests.
On each scheduled run of these workflows, I need to get some properties from the current workflow from my node.js code that is running. For example name.
How do I do that?

How to create bug or Notification in only one task/Job when other task/Job failed in an Agent in devops in Release Pipe line

I have an pipeline which will have few task mentioned in the image. I'm creating a bug work item when a particular task failed which is working fine using logic app.
Now my problem is I don't want to add every time new task for bug creation after each deployment task mentioned in the image.
Is there any way I can create only one bug work item based on failure in any of the task in the pipeline. may be in the last or somewhere..?
Not sure why you had to go the Logic app route as there is an option to do this with Azure Pipelines itself out of the box.
Navigate to {your pipeline} > Options as shown below:
If the build pipeline fails, you can automatically create a work item to track getting the problem fixed. You can specify the work item type. You can also select if you want to assign the work item to the requestor. For example, if this is a CI build, and a team member checks in some code that breaks the build, then the work item is assigned to that person.
Additional Fields: You can also set the value of other work item fields. For example:
Field Value
------- -------
System.Title Build $(Build.BuildNumber) failed
System.Reason Build failure
Check Build Options for more details.
UPDATE:
Doing this for Release Pipelines is not supported as an out of the box feature as of today. However, there are extensions available in the Visual Studio marketplace that can be used as alternatives until it is supported.
Here are two such extensions:
Create Bug on Release failure
Create Work Item
Another idea with PowerShell tasks is discussed here.

How to modify the "Issues" collection in the GetBuildDetails response in TFS 2017

We are building a custom Visual Studio build task to implement compliance validation of the builds defined by our developper teams.
The objective is to mark builds using "unauthorized" tasks, or failing to use mandatory tasks in a way that will be possible for a BuildCompleted servicehook to act upon later on.
We are creating a JSON structure describing the different business rules we want to enforce, and we have a service hook catching end-of-build events to create a tracability file that will mark the build artifacts as "deployable" or not.
I can see from the MS references that a Issue collection is returned with the GetBuildDetails responss that seems to list exactly the kind of information we'd like to pass along.
Anyone found a way to populate that property?
Thanks!
The solution is add additional information to the build result by using Logging Commands (e.g. ##vso[task.logissue]error/warning message)

Customizing TFS 2013 Build Process Template

I have added few arguments to the existing Build Process template, so I can pass those arguments to Powershell Script which was invoked as part of build customization. I had defined those values for arguments under build process tab but somehow those arguments value are not showing up whenever build was queued.
Please help..
In TFS 2013, the default build process template has included run script and add arguments, you can use it directly instead of customizing the build process template to invoke powershell scripts:
You need to add arguments in Process Parameter Metadata Editor, then you'll see these arguments on Process tab in build definition. Refer to this blog: http://www.ewaldhofman.nl/post/2010/04/27/Customize-Team-Build-2010-e28093-Part-2-Add-arguments-and-variables.aspx
Make sure you have checked in the custom build process template, and select the correct build process template in your build definition.
You can go to TFS web access to check Diagnostics log to see whether you can see the arguments you added. If you can see them on
Web Access, then your customization is correct. If you find you can
see the arguments on web access, but not in VS, try to change the
BuildMessageImportance of the variable to High.

How to Inject a Build Environment Variable Computed from a Jenkins Run Parameter?

I understand how to use the EnvInject plugin to compute variables from string parameters (the parameter name simply is an unbound variable in the groovy script performing the injection).
I want to use a Run Parameter - the parameter that contains the latest successful build of a project (or whichever build the user selects), but it appears that any of those are not available at the time the EnvInject plugin runs.
I guess I need to write groovy code to inspect the desired project myself and get the right build name directly from the model - except I can't do that, since the model lives on the master and the envInject plugin runs on the slave....
EnvInject can run at different times...
At node/master level (on startup, and available always).
At job startup, before SCM step (configured at the top of job configuration).
After SCM step (configured under "build environment" section).
As a build step.
You should either last or second-last options, if you want build parameters to be available
Lastly, there is another option to try. Get pre-scm-buildstep plugin. This allows to run any build step (including EnvInject), just before the SCM checkout. I've done a quick test, and the job parameters and their values are available at this stage.

Resources