سؤال

Setup:

  • Jenkins
  • NUnit
  • Selenium
  • Email-ext (Jenkins plugin)

We have a test suite in C# that does setup: it checks in TestRail for what tests exist in the test plan, and writes to a file that list of tests. The build in Jenkins has two build steps (after pull & build):

  1. Run the setup suite to get the list of tests to bother running.
  2. Run the suite, using the /runlist NUnit parameter to pull in that list.

This works fantastically when there are tests to be run.

However, due to [completely separate implementation], there will be times when that file is empty. Therefore, the NUnit result for the "run with list" build step:

Tests run: 0, Errors: 0, Failures: 0, Inconclusive: 0, Time: 0.010100375885762 seconds
Not run: 0, Invalid: 0, Ignored: 0, Skipped: 0

This tells Jenkins that this step failed:

C:\Program Files (x86)\Jenkins\jobs\[job_name]\workspace>exit 0 
Archiving artifacts
Recording NUnit tests results
No test report files were found. Configuration error?
Build step 'Publish NUnit test result report' changed build result to FAILURE
Email was triggered for: Failure
Sending email for trigger: Failure

What I want is one of two things:

  • At the very least, it would not send out a failure email.
  • Ideally, the result from the setup build step would tell the build to stop, as there's nothing to build. The "Aborted" email trigger would be sent.

How do I configure Jenkins/this build to have that happen?

هل كانت مفيدة؟

المحلول

I believe I've found an answer to my own question.

Steps:

  • Install the Conditional Build Step plugin.
  • Install the Fail The Build plugin.
  • Add a batch script that returns error code 1 if the tests-to-run file size is 0, or error code 0 otherwise.
  • Add a single conditional build step:
    • Execute Windows Batch Commands == the path to the batch file.
    • Set the build result == Unstable (or whatever).

My batch file code:

@echo off

REM Retrieve the build name.
set arg1=%1

REM Set the file name.
set file="C:\Path\To\TestsToRunFile\%arg1%.txt"

REM Get the file size.
FOR /F "usebackq" %%A IN ('%file%') DO set size=%%~zA

REM Exit codes based on the file size.
IF %size% EQU 0 (
    exit /b 0
) ELSE (
    exit /b 1
)
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top