Skip to content

Commit d197a6a

Browse files
committed
(CAT-2413) Defaults puppetcore agent version to newest if none given
When puppetcore is selected without a specified version, this change defaults to the latest 8.x version available. This prevents errors caused by the download site requiring a version parameter. Relates to CAT-2413
1 parent 3135977 commit d197a6a

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

tasks/install_powershell.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,15 @@ if (($collection -like '*puppetcore*-nightly*') -And -Not ($PSBoundParameters.Co
122122
$windows_source = 'https://nightlies.puppet.com/downloads'
123123
} elseif (($collection -like '*puppetcore*') -And -Not ($PSBoundParameters.ContainsKey('windows_source'))) {
124124
$windows_source = 'https://artifacts-puppetcore.puppet.com/v1/download'
125+
# Puppetcore requires a version to be specified, so we will use the latest version if not specified.
126+
# Or if the version is set to "latest".
127+
if ($version -eq "" || !$version || $version -eq "latest") {
128+
$response = Invoke-WebRequest -Uri "https://forgeapi.puppet.com/private/versions/puppet-agent" -UseBasicParsing
129+
$jsonData = $response.Content | ConvertFrom-Json
130+
$allVersions = $jsonData.PSObject.Properties.Name
131+
$version8x = $allVersions | Where-Object { $_ -like "8.*" }
132+
$version = $version8x | Sort-Object { [Version]$_ } | Select-Object -Last 1
133+
}
125134
}
126135

127136
if ($absolute_source) {

tasks/install_shell.sh

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -830,24 +830,33 @@ case $platform in
830830
"mac_os_x")
831831
info "Mac platform! Lets get you a DMG..."
832832
filetype="dmg"
833-
if test "$version" = "latest"; then
834-
filename="puppet-agent-latest.dmg"
835-
else
836-
filename="puppet-agent-${version}-1.osx${platform_version}.dmg"
837-
fi
838-
839833
arch="x86_64"
840834
if [[ $(uname -p) == "arm" ]]; then
841835
arch="arm64"
842836
fi
843837
if [[ "$collection" =~ "puppetcore" ]]; then
838+
# Puppetcore requires a version to be specified, so we will use the latest version if not specified.
839+
# Or if the version is set to "latest".
840+
if [[ -z "$version" || "$version" == "latest" ]]; then
841+
version=$(curl -sL https://forgeapi.puppet.com/private/versions/puppet-agent | \
842+
jq -r 'keys_unsorted |
843+
map(select(startswith("8."))) |
844+
max_by(split(".") | map(tonumber))')
845+
fi
846+
844847
dots=$(echo "${version}" | grep -o '\.' | wc -l)
845848
if (( dots >= 3 )); then
846-
download_url="${mac_source}?version=${version}&os_name=osx&os_version=${platform_version}&os_arch=${arch}&dev=true"
849+
download_url="${mac_source}?type=native&version=${version}&os_name=osx&os_version=${platform_version}&os_arch=${arch}&dev=true"
847850
else
848-
download_url="${mac_source}?version=${version}&os_name=osx&os_version=${platform_version}&os_arch=${arch}"
851+
download_url="${mac_source}?type=native&version=${version}&os_name=osx&os_version=${platform_version}&os_arch=${arch}"
849852
fi
850853
else
854+
if test "$version" = "latest"; then
855+
filename="puppet-agent-latest.dmg"
856+
else
857+
filename="puppet-agent-${version}-1.osx${platform_version}.dmg"
858+
fi
859+
851860
download_url="${mac_source}/mac/${collection}/${platform_version}/${arch}/${filename}"
852861
fi
853862
;;

0 commit comments

Comments
 (0)