Skip to content

Commit

Permalink
jenkins,win: add buildpulse support (#3653)
Browse files Browse the repository at this point in the history
This commit adds initial BuildPulse support by optionally uploading
test results there. If machine is not configured to connect to
BuildPulse, or if any condition is not met, the data will not be sent.
If the upload fails, the test job will just continue.

For now, this is a PoC and only Windows machines can upload results.
If we decide to move forward with it, other platforms will be added.

Refs: #3575
  • Loading branch information
StefanStojanovic committed Mar 27, 2024
1 parent 51ad778 commit 11ee0af
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 0 deletions.
108 changes: 108 additions & 0 deletions jenkins/scripts/windows/buildpulse.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
:: CODE TO SEND RESULTS TO BUILDPULSE IF MACHINE IS CONFIGURED
:: IF ANY REQUIRED CONDITION IS NOT MET IT WILL BE SKIPPED
echo "Preparing to send data to BuildPulse."

:: 1.Check organization and repository
echo "Checking organization and repository."

set "REQUIRED_ORGANIZATION=nodejs"
if not "%GITHUB_ORG%"=="%REQUIRED_ORGANIZATION%" (
echo "Organization set to %GITHUB_ORG%, %REQUIRED_ORGANIZATION% required. Cannot send results to BuildPulse."
exit /b 0
)
echo "Organization set to %GITHUB_ORG%."

set "REQUIRED_REPOSITORY=node"
if not "%REPO_NAME%"=="%REQUIRED_REPOSITORY%" (
echo "Repository set to %REPO_NAME%, %REQUIRED_REPOSITORY% required. Cannot send results to BuildPulse."
exit /b 0
)
echo "Repository set to %REPO_NAME%."

:: 2.Check test results
echo "Checking test results."

if "%1"=="" (
echo "No results provided to send to BuildPulse."
exit /b 0
)

if not exist %1 (
echo "No results found in %1 to send to BuildPulse."
exit /b 0
)

echo "Results found in %1."

:: 3.Check required environment variables
echo "Checking required environment variables."

if not defined BUILDPULSE_ACCESS_KEY_ID (
echo "BUILDPULSE_ACCESS_KEY_ID not set. Cannot send results to BuildPulse."
exit /b 0
)
echo "BUILDPULSE_ACCESS_KEY_ID is set."

if not defined BUILDPULSE_SECRET_ACCESS_KEY (
echo "BUILDPULSE_SECRET_ACCESS_KEY not set. Cannot send results to BuildPulse."
exit /b 0
)
echo "BUILDPULSE_SECRET_ACCESS_KEY is set."

if not defined BUILDPULSE_ACCOUNT_ID (
echo "BUILDPULSE_ACCOUNT_ID not set. Cannot send results to BuildPulse."
exit /b 0
)
echo "BUILDPULSE_ACCOUNT_ID is set."

if not defined BUILDPULSE_REPOSITORY_ID (
echo "BUILDPULSE_REPOSITORY_ID not set. Cannot send results to BuildPulse."
exit /b 0
)
echo "BUILDPULSE_REPOSITORY_ID is set."

:: 4.Check test-reporter tool
echo "Checking test-reporter tool."

set "TEST_REPORTER_PATH=C:\test-reporter-windows-amd64.exe"
if not exist %TEST_REPORTER_PATH% (
echo "Cannot find test-reporter tool in %TEST_REPORTER_PATH%. Cannot send results to BuildPulse."
exit /b 0
)
echo "Test-reporter tool found in %TEST_REPORTER_PATH%."

:: 5.Set test-reporter tool required environment variables
echo "Setting test-reporter tool required environment variables."

set "GIT_BRANCH=%GIT_REMOTE_REF%"
:: GIT_COMMIT is already set by Jenkins
:: BUILD_URL is already set by Jenkins
set "ORGANIZATION_NAME=%GITHUB_ORG%"
set "REPOSITORY_NAME=%REPO_NAME%"

echo "GIT_BRANCH set to %GIT_BRANCH%."
echo "GIT_COMMIT set to %GIT_COMMIT%."
echo "BUILD_URL set to %BUILD_URL%."
echo "ORGANIZATION_NAME set to %ORGANIZATION_NAME%."
echo "REPOSITORY_NAME set to %REPOSITORY_NAME%."

:: GIT_URL is required for the test-reporter tool
:: We can hardcode it since we enforce nodejs/node
if "%GIT_URL%"=="" set "GIT_URL=https://github.com/%ORGANIZATION_NAME%/%REPOSITORY_NAME%"
echo "GIT_URL set to %GIT_URL%."

:: 6.Send results to BuildPulse
echo "Sending data to BuildPulse."

:: Add available tags for easier navigation in BuildPulse
set "TAGS=%NODE_NAME% %nodes% v%NODEJS_MAJOR_VERSION%"
if defined NODEJS_VERSION (
set "TAGS=%TAGS% v%NODEJS_VERSION%"
)

:: Edit BUILD_URL to enable better grouping in BuildPulse
set "BUILD_URL_BACKUP=%BUILD_URL%"
for /f "usebackq delims=" %%i in (`powershell -File "%~dp0modify-build-url.ps1" -BUILD_URL "%BUILD_URL%"`) do set "BUILD_URL=%%i"
%TEST_REPORTER_PATH% submit %1 --account-id %BUILDPULSE_ACCOUNT_ID% --repository-id %BUILDPULSE_REPOSITORY_ID% --tags "%TAGS%"
set "BUILD_URL=%BUILD_URL_BACKUP%"
exit /b 0
17 changes: 17 additions & 0 deletions jenkins/scripts/windows/modify-build-url.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# USED FOR MODIFYING BUILD_URL SENT TO BUILDPULSE FOR BETTER GROUPING
param (
[string]$BUILD_URL
)

# If url ends with "/" we have to correct splitting
$CORRECTION = 0
if ($BUILD_URL -Match '/$') {
$CORRECTION = 1
}

# We need to remove configuration part from url
$URL_PARTS = $BUILD_URL -Split '/'
$URL_PARTS = $URL_PARTS[0..($URL_PARTS.Length - (3 + $CORRECTION))] + $URL_PARTS[-(1 + $CORRECTION)]
$BUILD_URL = $URL_PARTS -Join '/'

Write-Output $BUILD_URL
6 changes: 6 additions & 0 deletions jenkins/scripts/windows/test.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,16 @@ if exist test.tap (
tap2junit -i test.tap -o js-tests.junit.xml
if errorlevel 1 exit /b
)
if exist js-tests.junit.xml (
call %~dp0buildpulse.cmd js-tests.junit.xml
)
if exist cctest.tap (
tap2junit -i cctest.tap -o cctest.junit.xml
if errorlevel 1 exit /b
)
if exist cctest.junit.xml (
call %~dp0buildpulse.cmd cctest.junit.xml
)

:: The JUnit Plugin only marks the job as Unstable when it finds any kind of failure, including flaky tests.
:: We need to use the return code of vcbuild.bat to fail the job when there are real failures.
Expand Down

0 comments on commit 11ee0af

Please sign in to comment.