From 62639e3a6ebd6f4580195ec945bb0da4dcf718be Mon Sep 17 00:00:00 2001 From: Branden Clark Date: Mon, 16 Dec 2024 12:02:21 -0500 Subject: [PATCH] Build FIPS Agent chocolatey package (#32070) --- .gitlab-ci.yml | 4 +- .gitlab/choco_build/choco_build.yml | 36 ++- .../offline}/datadog-agent-offline.nuspec | 2 +- .../offline/tools}/VERIFICATION.txt | 0 .../offline/tools}/chocolateyinstall.ps1 | 0 .../online}/datadog-agent-online.nuspec | 2 +- .../online/tools}/VERIFICATION.txt | 0 .../online/tools}/chocolateyinstall.ps1 | 0 .../online/datadog-fips-agent-online.nuspec | 31 +++ .../online/tools/VERIFICATION.txt | 5 + .../online/tools/chocolateyinstall.ps1 | 27 ++ .../Generate-Chocolatey-Package.ps1 | 230 ++++++++++++------ tasks/winbuildscripts/chocopack.bat | 11 - 13 files changed, 258 insertions(+), 90 deletions(-) rename chocolatey/{ => datadog-agent/offline}/datadog-agent-offline.nuspec (97%) rename chocolatey/{tools-offline => datadog-agent/offline/tools}/VERIFICATION.txt (100%) rename chocolatey/{tools-offline => datadog-agent/offline/tools}/chocolateyinstall.ps1 (100%) rename chocolatey/{ => datadog-agent/online}/datadog-agent-online.nuspec (97%) rename chocolatey/{tools-online => datadog-agent/online/tools}/VERIFICATION.txt (100%) rename chocolatey/{tools-online => datadog-agent/online/tools}/chocolateyinstall.ps1 (100%) create mode 100644 chocolatey/datadog-fips-agent/online/datadog-fips-agent-online.nuspec create mode 100644 chocolatey/datadog-fips-agent/online/tools/VERIFICATION.txt create mode 100644 chocolatey/datadog-fips-agent/online/tools/chocolateyinstall.ps1 delete mode 100644 tasks/winbuildscripts/chocopack.bat diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 05351cee64faf..8d256885317c3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -584,8 +584,10 @@ workflow: when: always .on_deploy_stable_or_beta_repo_branch: + - !reference [.except_mergequeue] - <<: *if_not_stable_or_beta_repo_branch - when: never + when: manual + allow_failure: true - <<: *if_deploy .on_deploy_stable_or_beta_repo_branch_manual: diff --git a/.gitlab/choco_build/choco_build.yml b/.gitlab/choco_build/choco_build.yml index 97ef76cd478f0..8ec5bac814d18 100644 --- a/.gitlab/choco_build/choco_build.yml +++ b/.gitlab/choco_build/choco_build.yml @@ -14,8 +14,13 @@ windows_choco_offline_7_x64: script: - $ErrorActionPreference = "Stop" - Get-ChildItem omnibus\pkg - - copy omnibus\pkg\*.msi .\chocolatey\tools-offline\ - - docker run --rm -v "$(Get-Location):c:\mnt" registry.ddbuild.io/ci/datadog-agent-buildimages/windows_1809_${ARCH}${Env:DATADOG_AGENT_WINBUILDIMAGES_SUFFIX}:${Env:DATADOG_AGENT_WINBUILDIMAGES} c:\mnt\tasks\winbuildscripts\chocopack.bat offline + - copy omnibus\pkg\*.msi .\chocolatey\datadog-agent\offline\tools\ + - > + docker run --rm + -v "$(Get-Location):c:\mnt" + -e AWS_NETWORKING=true + registry.ddbuild.io/ci/datadog-agent-buildimages/windows_1809_${ARCH}${Env:DATADOG_AGENT_WINBUILDIMAGES_SUFFIX}:${Env:DATADOG_AGENT_WINBUILDIMAGES} + powershell.exe -C "C:\mnt\tasks\winbuildscripts\Generate-Chocolatey-Package.ps1 -InstallMethod offline -Flavor $FLAVOR -InstallDeps 1" - If ($lastExitCode -ne "0") { throw "Previous command returned $lastExitCode" } - copy build-out\*.nupkg omnibus\pkg artifacts: @@ -24,12 +29,11 @@ windows_choco_offline_7_x64: - omnibus/pkg # The online version of the choco job gets the msi package through the gitlab artifacts -windows_choco_online_7_x64: +.windows_choco_online_7_x64: rules: !reference [.on_deploy_stable_or_beta_repo_branch] stage: choco_and_install_script_build tags: ["runner:windows-docker", "windowsversion:1809"] - needs: ["deploy_packages_windows-x64-7"] variables: ARCH: "x64" script: @@ -43,10 +47,12 @@ windows_choco_online_7_x64: - > docker run --rm -v "$(Get-Location):c:\mnt" + -e CI_PROJECT_NAME=${CI_PROJECT_NAME} -e CI_PIPELINE_ID=${CI_PIPELINE_ID} -e BUCKET_BRANCH="$BUCKET_BRANCH" + -e AWS_NETWORKING=true registry.ddbuild.io/ci/datadog-agent-buildimages/windows_1809_${ARCH}${Env:DATADOG_AGENT_WINBUILDIMAGES_SUFFIX}:${Env:DATADOG_AGENT_WINBUILDIMAGES} - c:\mnt\tasks\winbuildscripts\chocopack.bat online c:\mnt\temp + powershell.exe -C "C:\mnt\tasks\winbuildscripts\Generate-Chocolatey-Package.ps1 -InstallMethod online -MSIDirectory c:\mnt\temp -Flavor $FLAVOR -InstallDeps 1" - If ($lastExitCode -ne "0") { throw "Previous command returned $lastExitCode" } - Remove-Item -Path "temp\" -Recurse -Force - copy build-out\*.nupkg omnibus\pkg @@ -58,3 +64,23 @@ windows_choco_online_7_x64: - omnibus/pkg # Sometimes Chocolatey is flakey retry: 2 + +windows_choco_online_7_x64: + extends: .windows_choco_online_7_x64 + # On dev/PR branches: + # - if the job is run manually it will create a package, but before the + # package can be installed, the deploy_windows_testing-a7 job must + # be run to push the MSI to the dd-agent-mstesting bucket. + needs: ["windows_msi_and_bosh_zip_x64-a7"] + variables: + FLAVOR: "datadog-agent" + +windows_choco_online_7_x64-fips: + extends: .windows_choco_online_7_x64 + # On dev/PR branches: + # - if the job is run manually it will create a package, but before the + # package can be installed, the deploy_windows_testing-a7-fips job must + # be run to push the MSI to the dd-agent-mstesting bucket. + needs: ["windows_msi_and_bosh_zip_x64-a7-fips"] + variables: + FLAVOR: "datadog-fips-agent" diff --git a/chocolatey/datadog-agent-offline.nuspec b/chocolatey/datadog-agent/offline/datadog-agent-offline.nuspec similarity index 97% rename from chocolatey/datadog-agent-offline.nuspec rename to chocolatey/datadog-agent/offline/datadog-agent-offline.nuspec index d049625a0ef3b..aedf9555a1c51 100644 --- a/chocolatey/datadog-agent-offline.nuspec +++ b/chocolatey/datadog-agent/offline/datadog-agent-offline.nuspec @@ -26,6 +26,6 @@ For example, to set the API key you may run: $release_notes$ - + diff --git a/chocolatey/tools-offline/VERIFICATION.txt b/chocolatey/datadog-agent/offline/tools/VERIFICATION.txt similarity index 100% rename from chocolatey/tools-offline/VERIFICATION.txt rename to chocolatey/datadog-agent/offline/tools/VERIFICATION.txt diff --git a/chocolatey/tools-offline/chocolateyinstall.ps1 b/chocolatey/datadog-agent/offline/tools/chocolateyinstall.ps1 similarity index 100% rename from chocolatey/tools-offline/chocolateyinstall.ps1 rename to chocolatey/datadog-agent/offline/tools/chocolateyinstall.ps1 diff --git a/chocolatey/datadog-agent-online.nuspec b/chocolatey/datadog-agent/online/datadog-agent-online.nuspec similarity index 97% rename from chocolatey/datadog-agent-online.nuspec rename to chocolatey/datadog-agent/online/datadog-agent-online.nuspec index d3cf3133a1a98..73f96bfb83871 100644 --- a/chocolatey/datadog-agent-online.nuspec +++ b/chocolatey/datadog-agent/online/datadog-agent-online.nuspec @@ -26,6 +26,6 @@ For example, to set the API key you may run: $release_notes$ - + diff --git a/chocolatey/tools-online/VERIFICATION.txt b/chocolatey/datadog-agent/online/tools/VERIFICATION.txt similarity index 100% rename from chocolatey/tools-online/VERIFICATION.txt rename to chocolatey/datadog-agent/online/tools/VERIFICATION.txt diff --git a/chocolatey/tools-online/chocolateyinstall.ps1 b/chocolatey/datadog-agent/online/tools/chocolateyinstall.ps1 similarity index 100% rename from chocolatey/tools-online/chocolateyinstall.ps1 rename to chocolatey/datadog-agent/online/tools/chocolateyinstall.ps1 diff --git a/chocolatey/datadog-fips-agent/online/datadog-fips-agent-online.nuspec b/chocolatey/datadog-fips-agent/online/datadog-fips-agent-online.nuspec new file mode 100644 index 0000000000000..90b6de924c628 --- /dev/null +++ b/chocolatey/datadog-fips-agent/online/datadog-fips-agent-online.nuspec @@ -0,0 +1,31 @@ + + + + datadog-fips-agent + $version$ + https://github.com/DataDog/datadog-agent/tree/main/chocolatey + Datadog + Datadog FIPS Agent + Datadog + https://github.com/DataDog/datadog-agent + https://datadog-prod.imgix.net/img/dd_logo_70x75.png + $copyright$ + https://raw.githubusercontent.com/DataDog/datadog-agent/main/LICENSE + true + https://docs.datadoghq.com + datadog agent monitoring admin + The Datadog FIPS Agent for Microsoft Windows + The Datadog FIPS Agent faithfully collects events and metrics and brings them to Datadog on your behalf so that you can do something useful with your monitoring and performance data. + +## Package settings + +You may set [custom settings](https://docs.datadoghq.com/agent/basic_agent_usage/windows/?tab=commandline#installation) to the Agent when installing by using the [`--installer-arguments` option of `choco install`](https://chocolatey.org/docs/getting-started#overriding-default-install-directory-or-other-advanced-install-concepts). + +For example, to set the API key you may run: +`choco install -ia="APIKEY=""YOUR_DATADOG_API_KEY""" datadog-fips-agent` + $release_notes$ + + + + + diff --git a/chocolatey/datadog-fips-agent/online/tools/VERIFICATION.txt b/chocolatey/datadog-fips-agent/online/tools/VERIFICATION.txt new file mode 100644 index 0000000000000..b13ab096f9a76 --- /dev/null +++ b/chocolatey/datadog-fips-agent/online/tools/VERIFICATION.txt @@ -0,0 +1,5 @@ +VERIFICATION +Verification is intended to assist the Chocolatey moderators and community in verifying that this package's contents are trustworthy. + +This package is published by Datadog itself. +The binaries are identical to other package types for the Datadog FIPS Agent. diff --git a/chocolatey/datadog-fips-agent/online/tools/chocolateyinstall.ps1 b/chocolatey/datadog-fips-agent/online/tools/chocolateyinstall.ps1 new file mode 100644 index 0000000000000..d928fdf7bff78 --- /dev/null +++ b/chocolatey/datadog-fips-agent/online/tools/chocolateyinstall.ps1 @@ -0,0 +1,27 @@ +$ErrorActionPreference = 'Stop'; + +$toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)" +$packageArgs = @{ + packageName = $env:ChocolateyPackageName + unzipLocation = $toolsDir + fileType = 'msi' + # Note: Url is replaced at build time with the full URL to the MSI + url64bit = $__url_from_ci__ + checksum64 = $__checksum_from_ci__ + checksumType = 'sha256' + softwareName = "Datadog FIPS Agent" + silentArgs = "/qn /norestart /l*v `"$($env:TEMP)\$($packageName).$($env:chocolateyPackageVersion).MsiInstall.log`"" + validExitCodes= @(0, 3010, 1641) +} +Install-ChocolateyPackage @packageArgs + +$installInfo = @" +--- +install_method: + tool: chocolatey + tool_version: chocolatey-$($env:CHOCOLATEY_VERSION) + installer_version: chocolatey_package-online +"@ + +$appDataDir = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Datadog\Datadog Agent").ConfigRoot +Out-File -FilePath $appDataDir\install_info -InputObject $installInfo diff --git a/tasks/winbuildscripts/Generate-Chocolatey-Package.ps1 b/tasks/winbuildscripts/Generate-Chocolatey-Package.ps1 index 9780b4a3a4103..991317602152f 100644 --- a/tasks/winbuildscripts/Generate-Chocolatey-Package.ps1 +++ b/tasks/winbuildscripts/Generate-Chocolatey-Package.ps1 @@ -1,97 +1,185 @@ +<# +.SYNOPSIS +Generates a Chocolatey package for the Datadog Agent. + +.PARAMETER installMethod +Specifies the installation method. Valid values are "offline" and "online". This parameter is mandatory. + +.PARAMETER msiDirectory +Specifies the directory containing the MSI file that will be used to calculate the checksum. This parameter is mandatory when the installMethod is "online". + +.PARAMETER Flavor +Specifies the flavor of the Datadog Agent. The default value is "datadog-agent". + +.PARAMETER VersionOverride +Overrides the Agent version when building packages locally for testing. + +.PARAMETER InstallDeps +Indicates whether to install dependencies. The default value is $true. + +.EXAMPLE +.\Generate-Chocolatey-Package.ps1 -installMethod online -Flavor datadog-agent -VersionOverride "7.62.0" -msiDirectory C:\mnt\omnibus\pkg\ + +Generates a chocolatey package for 7.62.0, requires the MSI file to be present in MSIDirectory. + +.EXAMPLE +$env:CI_PIPELINE_ID="50910739"; .\Generate-Chocolatey-Package.ps1 -installMethod online -Flavor datadog-agent -VersionOverride "7.62.0-devel.git.276.e59b1b3.pipeline.50910739" -msiDirectory C:\mnt\omnibus\pkg + +Generates a chocolatey package for PR/devel build 7.62.0-devel.git.276.e59b1b3.pipeline.50910739, requires the MSI file to be present in MSIDirectory. +The generated chocolatey package requires the MSI be uploaded to the dd-agent-mstesting bucket. +#> Param( - [Parameter(Mandatory=$true,Position=0)] + [Parameter(Mandatory=$true)] [ValidateSet("offline", "online")] [String] $installMethod, - [Parameter(Mandatory=$false,Position=1)] - [String] - $msiDirectory + [Parameter(Mandatory=$false)] + [String] + $msiDirectory, + + [Parameter(Mandatory=$false)] + [ValidateSet("datadog-agent", "datadog-fips-agent")] + [String] + $Flavor = "datadog-agent", + + [Parameter(Mandatory=$false)] + [String] + $VersionOverride, + + [bool] $InstallDeps = $true ) $ErrorActionPreference = 'Stop'; Set-Location c:\mnt -# Install chocolatey binary -$env:chocolateyUseWindowsCompression = 'true'; Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) - -# Install dev tools, including invoke -pip3 install -r requirements.txt +if ($InstallDeps) { + # Install chocolatey + $env:chocolateyUseWindowsCompression = 'true'; Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) + # Install dev tools, including invoke + pip3 install -r requirements.txt +} -$outputDirectory = "c:\mnt\build-out" -$rawAgentVersion = (inv agent.version --url-safe --major-version 7) +$repoRoot = "C:\mnt" +$outputDirectory = "$repoRoot\build-out" +if (![string]::IsNullOrEmpty($VersionOverride)) { + $rawAgentVersion = $VersionOverride +} else { + $rawAgentVersion = (inv agent.version --url-safe --major-version 7) +} $copyright = "Datadog {0}" -f (Get-Date).Year $releasePattern = "(\d+\.\d+\.\d+)" $releaseCandidatePattern = "(\d+\.\d+\.\d+)-rc\.(\d+)" $develPattern = "(\d+\.\d+\.\d+)-devel\.git\.\d+\.(.+)" -$nuspecFile = "c:\mnt\chocolatey\datadog-agent-online.nuspec" -$licensePath = "c:\mnt\chocolatey\tools-online\LICENSE.txt" -$installScript = "c:\mnt\chocolatey\tools-online\chocolateyinstall.ps1" - -if ($installMethod -eq "offline") { - $nuspecFile = "c:\mnt\chocolatey\datadog-agent-offline.nuspec" - $licensePath = "c:\mnt\chocolatey\tools-offline\LICENSE.txt" +# Build the package in a temporary directory +# Some of the build steps modify the package source, so we don't want to do this in the source directory +$buildTempDir = [System.IO.Path]::GetTempPath() + "\datadog-choco-build" +if (Test-Path $buildTempDir) { + Remove-Item -Recurse -Force $buildTempDir } - -if ($rawAgentVersion -match $releaseCandidatePattern) { - $agentVersionMatches = $rawAgentVersion | Select-String -Pattern $releaseCandidatePattern - $agentVersion = "{0}-rc-{1}" -f $agentVersionMatches.Matches.Groups[1], $agentVersionMatches.Matches.Groups[2].Value - # We don't have release notes for RCs but this way the user can always see what commits are included in this RC - $releaseNotes = "https://github.com/DataDog/datadog-agent/releases/tag/{0}-rc.{1}" -f $agentVersionMatches.Matches.Groups[1], $agentVersionMatches.Matches.Groups[2] - $url = "https://s3.amazonaws.com/dd-agent-mstesting/builds/beta/ddagent-cli-$($agentVersionMatches.Matches.Groups[1])-rc.$($agentVersionMatches.Matches.Groups[2]).msi" -} elseif ($rawAgentVersion -match $develPattern) { - if ($installMethod -eq "online") { - # We don't publish online chocolatey packages for dev branches, error out - Write-Host "Chocolatey packages are not built for dev branches aborting" - exit 2 +New-Item -ItemType Directory -Path $buildTempDir | Out-Null +Push-Location -Path $buildTempDir +try { + # Set the artifact name and package source based on the flavor + if ($Flavor -eq "datadog-agent") { + # For historical reasons, use a different artifact name for the datadog-agent flavor + # See agent-release-management for more details + $artifactName = "ddagent-cli" + $packageSource = "$repoRoot\chocolatey\datadog-agent\$installMethod" + $nuspecFile = "datadog-agent-$installMethod.nuspec" + } elseif ($Flavor -eq "datadog-fips-agent") { + if ($installMethod -eq "offline") { + Write-Error "Offline install method not supported for flavor $Flavor" + exit 1 + } + $artifactName = "datadog-fips-agent" + $packageSource = "$repoRoot\chocolatey\datadog-fips-agent\online" + $nuspecFile = "datadog-fips-agent-online.nuspec" + } else { + Write-Error "Unknown flavor $Flavor" + exit 1 } - $agentVersionMatches = $rawAgentVersion | Select-String -Pattern $develPattern - $agentVersion = "{0}-devel-{1}" -f $agentVersionMatches.Matches.Groups[1], $agentVersionMatches.Matches.Groups[2].Value - # We don't have release notes for devel, so point it to the generic url - $releaseNotes = "https://github.com/DataDog/datadog-agent/releases" -} elseif ($rawAgentVersion -match $releasePattern) { - $agentVersionMatches = $rawAgentVersion | Select-String -Pattern $releasePattern - $agentVersion = $agentVersionMatches.Matches.Groups[1].Value - $releaseNotes = "https://github.com/DataDog/datadog-agent/releases/tag/$agentVersion" - $url = "https://s3.amazonaws.com/ddagent-windows-stable/ddagent-cli-$($agentVersion).msi" -} else { - Write-Host "Unknown agent version '$rawAgentVersion', aborting" - exit 3 -} -Invoke-WebRequest -Uri "https://raw.githubusercontent.com/DataDog/datadog-agent/main/LICENSE" -OutFile $licensePath - -Write-Host "Generating Chocolatey $installMethod package version $agentVersion in $outputDirectory" + # These files/directories are referenced in the nuspec file + $licensePath = "tools\LICENSE.txt" + $installScript = "tools\chocolateyinstall.ps1" + + # Copy package source to build temp dir + Copy-Item -Recurse -Force -Path $packageSource\* -Destination $buildTempDir + Copy-Item -Force -Path $repoRoot\LICENSE -Destination $licensePath + + # Generate URLs based on the Agent version + if ($rawAgentVersion -match $releaseCandidatePattern) { + $agentVersionMatches = $rawAgentVersion | Select-String -Pattern $releaseCandidatePattern + $agentVersion = "{0}-rc-{1}" -f $agentVersionMatches.Matches.Groups[1], $agentVersionMatches.Matches.Groups[2].Value + # We don't have release notes for RCs but this way the user can always see what commits are included in this RC + $releaseNotes = "https://github.com/DataDog/datadog-agent/releases/tag/{0}-rc.{1}" -f $agentVersionMatches.Matches.Groups[1], $agentVersionMatches.Matches.Groups[2] + $url = "https://s3.amazonaws.com/dd-agent-mstesting/builds/beta/$artifactName-$($agentVersionMatches.Matches.Groups[1])-rc.$($agentVersionMatches.Matches.Groups[2]).msi" + } elseif ($rawAgentVersion -match $develPattern) { + if ($installMethod -eq "online") { + # For devel builds/branches, use the dd-agent-mstesting bucket URL + # This allows us to build and test the package in PRs, and locally + # by using the `-VersionOverride` param. + if ([string]::IsNullOrEmpty($env:CI_PIPELINE_ID)) { + Write-Error "CI_PIPELINE_ID is not set, aborting" + exit 1 + } else { + if ($rawAgentVersion -notmatch $env:CI_PIPELINE_ID) { + Write-Error "CI_PIPELINE_ID is not found in the agent version, aborting" -ErrorAction Continue + if ([string]::IsNullOrEmpty($env:BUCKET_BRANCH)) { + # inv agent.version requires BUCKET_BRANCH to be set when including pipeline in version + Write-Error "BUCKET_BRANCH is not set, if you are running this locally, set `$env:BUCKET_BRANCH='dev' or pass the -VersionOverride parameter" -ErrorAction Continue + } + exit 1 + } + $url = "https://s3.amazonaws.com/dd-agent-mstesting/pipelines/A7/$env:CI_PIPELINE_ID/$flavor-$rawAgentVersion-1-x86_64.msi" + } + } + $agentVersionMatches = $rawAgentVersion | Select-String -Pattern $develPattern + $agentVersion = "{0}-devel-{1}" -f $agentVersionMatches.Matches.Groups[1], $agentVersionMatches.Matches.Groups[2].Value + # We don't have release notes for devel, so point it to the generic url + $releaseNotes = "https://github.com/DataDog/datadog-agent/releases" + } elseif ($rawAgentVersion -match $releasePattern) { + $agentVersionMatches = $rawAgentVersion | Select-String -Pattern $releasePattern + $agentVersion = $agentVersionMatches.Matches.Groups[1].Value + $releaseNotes = "https://github.com/DataDog/datadog-agent/releases/tag/$agentVersion" + $url = "https://s3.amazonaws.com/ddagent-windows-stable/$artifactName-$($agentVersion).msi" + } else { + Write-Host "Unknown agent version '$rawAgentVersion', aborting" + exit 1 + } -if (!(Test-Path $outputDirectory)) { - New-Item -ItemType Directory -Path $outputDirectory -} + Write-Host "Generating Chocolatey $installMethod package $flavor version $agentVersion in $(Get-Location)" -if ($installMethod -eq "online") { - try { - $tempMsi = Join-Path -Path "$msiDirectory" "datadog-agent-$rawAgentVersion-1-x86_64.msi" - if (!(Test-Path $tempMsi)) { - Write-Host "Error: Could not find MSI file in $tempMsi" - Get-ChildItem "$msiDirectory" - exit 1 + # Template the install script with the URL and checksum + if ($installMethod -eq "online") { + try { + $tempMsi = Join-Path -Path "$msiDirectory" "$flavor-$rawAgentVersion-1-x86_64.msi" + if (!(Test-Path $tempMsi)) { + Write-Host "Error: Could not find MSI file in $tempMsi" + Get-ChildItem "$msiDirectory" + exit 1 + } + $checksum = (Get-FileHash $tempMsi -Algorithm SHA256).Hash + } + catch { + Write-Host "Error: Could not generate checksum for package $($tempMsi): $($_)" + exit 1 } - $checksum = (Get-FileHash $tempMsi -Algorithm SHA256).Hash - } - catch { - Write-Host "Error: Could not generate checksum for package $($tempMsi): $($_)" - exit 4 + # Set the $url in the install script + (Get-Content $installScript).replace('$__url_from_ci__', '"' + $url + '"').replace('$__checksum_from_ci__', '"' + $checksum + '"') | Set-Content $installScript } - # Set the $url in the install script - (Get-Content $installScript).replace('$__url_from_ci__', '"' + $url + '"').replace('$__checksum_from_ci__', '"' + $checksum + '"') | Set-Content $installScript -} - -Write-Host "Generated nupsec file:" -Write-Host (Get-Content $installScript | Out-String) -Write-Host choco pack --out=$outputDirectory $nuspecFile --version $agentVersion release_notes=$releaseNotes copyright=$copyright -choco pack --out=$outputDirectory $nuspecFile --version $agentVersion release_notes=$releaseNotes copyright=$copyright + Write-Host "Generated nuspec file:" + Write-Host (Get-Content $installScript | Out-String) -# restore installScript (useful for local testing/deployment) -git checkout $installScript + if (!(Test-Path $outputDirectory)) { + New-Item -ItemType Directory -Path $outputDirectory + } + Write-Host choco pack --out=$outputDirectory $nuspecFile --version $agentVersion release_notes=$releaseNotes copyright=$copyright + choco pack --out=$outputDirectory $nuspecFile --version $agentVersion release_notes=$releaseNotes copyright=$copyright +} finally { + Pop-Location +} diff --git a/tasks/winbuildscripts/chocopack.bat b/tasks/winbuildscripts/chocopack.bat deleted file mode 100644 index df8915ae14698..0000000000000 --- a/tasks/winbuildscripts/chocopack.bat +++ /dev/null @@ -1,11 +0,0 @@ -if not exist c:\mnt\ goto nomntdir - -@echo c:\mnt found, continuing - -Powershell -C "C:\mnt\tasks\winbuildscripts\Generate-Chocolatey-Package.ps1 %1 %2" || exit /b 1 -goto :EOF - -:nomntdir -@echo directory not mounted, parameters incorrect -exit /b 2 -goto :EOF