Get today's Jenkins builds and and check if there are any success builds using PowerShell

34 Views Asked by At

I am trying to get if there are any success builds in today's date.

I am able to check all builds and get success builds info using the code below, but I am unable to filter and loop within today's builds only, instead of looping through all builds.

$successInfo = $false
    foreach ($build in $buildsInfo) {
        $buildDate = Get-Date($build.timestamp) -Format "yyyy-MM-dd"
        if ($build.result -eq "SUCCESS" -and $buildDate -eq $currentDate) {
            $successInfo = $true
            break
        }
    }

To check today's build I tried different approaches; below is one of them:

$startOfDay = (Get-Date).Date.ToShortDateString()
$todaysBuilds = $commitStageInfo.builds | Where-Object { (Get-Date($_.timestamp) -match $startOfDay) }

Note: My Jenkins build's timestamp is in timestamp=1711064553748 format.

0

There are 0 best solutions below