Adding build validation to a Jenkins job

Build validation allows you to automatically verify target builds to determine whether they completed successfully or experienced unanticipated issues. If a problem occurs (for example, a target fails to publish or includes errors such as broken links or missing source files), then build validation immediately notifies either an administrator or project authors (depending on the type of issue) so that the problem can be rapidly resolved. Before adding build validation to a job you must have completed both of these procedures:

To add build validation to a Jenkins job

  1. If you are not already displaying the Jenkins dashboard in a browser, navigate to the Jenkins URL (for example, http://localhost:8080, if working on the Jenkins host computer), and then log in as the administrator user you created during installation.
  1. On the dashboard, click the name of the job you want to validate.
  2. On the sidebar menu, click Configure.
  3. Click the Post-build Actions tab, and then in the Add post-build action list, select Execute scripts.
  4. Click Add generic script file.
  5. In the Generic script file path box, specify the path of the ValidateBuilds.cmd script that you downloaded previously and pass in these arguments:
  1. The full path to the BuildValidation.ps1 script that you downloaded previously.
  2. The path of the current Jenkins build workspace (you can use the $WORKSPACE environment variable to define this value).
  3. The name of the project you want to validate. The project name that you include in this value must correspond to the value of a name property defined in the buildConfiguration.json file (see Customizing the buildConfiguration.json file).

For example:

$WORKSPACE\myRepository\scripts\Jenkins\BuildValidation\BuildValidation.cmd $WORKSPACE\myRepository\scripts\Jenkins\BuildValidation\BuildValidation.ps1 $WORKSPACE "MyProject"

The above command assumes the that the BuildValidation.cmd script and BuildValidation.ps1 files have been saved in the Git repository (in this example, named myRepository), in the scripts\Jenkins\BuildValidation folder. The script passes in the current Jenkin's job workspace (by using the Jenkins environment variable $WORKSPACE) and instructs the script to perform validation for the project named MyProject.

  1. In the If build was list, select these states:
  • SUCCESS
  • UNSTABLE
  • FAILURE
  • NOT_BUILT

This causes the validation to be performed in all cases except when someone manually cancels the running Jenkins job.

  1. Click Save.

You have now defined build validation for the job. To test the validation, you can manually start the job. Note that the validation does not send any notifications unless a warning or error occurs during the build (that is, the build results in either a failure or unstable build outcome on the Jenkins dashboard).

If an author receives notification that a warning or error occurred, they can troubleshoot and fix the problem on their own computer, and without needing to build locally.