Skip to content

Commit bf778de

Browse files
authored
Merge pull request #307 from chocolatey/QSG-306
Upgrade CCM .NET Dependency Packages & Jenkins Plugins
2 parents 8085ea2 + 5dc9b48 commit bf778de

5 files changed

Lines changed: 127 additions & 51 deletions

File tree

OfflineInstallPreparation.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ foreach ($Plugin in (Get-Content $PSScriptRoot\files\jenkins.json | ConvertFrom-
150150
OutFile = Join-Path $PluginsWorkingDirectory "$($Plugin.Name).hpi"
151151
}
152152
if ($Plugin.Version -and $Plugin.Version -ne 'latest') {
153-
$RestArgs.Uri = "https://updates.jenkins-ci.org/download/plugins/$($Plugin.Name)/$($Plugin.Version)/$($Plugin.Name).hpi"
153+
$RestArgs.Uri = "https://updates.jenkins.io/download/plugins/$($Plugin.Name)/$($Plugin.Version)/$($Plugin.Name).hpi"
154154
}
155155
if (-not (Test-Path $RestArgs.OutFile)) {
156156
Invoke-WebRequest @RestArgs -UseBasicParsing

files/chocolatey.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
{ "name": "chocolatey" },
1515
{ "name": "chocolateygui.extension" },
1616
{ "name": "chocolateygui" },
17-
{ "name": "dotnet-8.0-aspnetruntime", "version": "8.0.16" },
18-
{ "name": "dotnet-8.0-runtime", "version": "8.0.16" },
19-
{ "name": "dotnet-aspnetcoremodule-v2", "version": "18.0.25074" },
17+
{ "name": "dotnet-8.0-aspnetruntime", "version": "8.0.22" },
18+
{ "name": "dotnet-8.0-runtime", "version": "8.0.22" },
19+
{ "name": "dotnet-aspnetcoremodule-v2", "version": "18.0.25301" },
2020
{ "name": "dotnetfx" },
2121
{ "name": "jenkins" },
2222
{ "name": "KB2919355", "internalize": false },

files/jenkins.json

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,34 @@
11
{
22
"plugins": [
33
{ "name": "apache-httpcomponents-client-4-api", "version": "4.5.14-269.vfa_2321039a_83" },
4-
{ "name": "asm-api", "version": "9.8-135.vb_2239d08ee90" },
5-
{ "name": "bouncycastle-api", "version": "2.30.1.80-256.vf98926042a_9b_" },
6-
{ "name": "branch-api", "version": "2.1217.v43d8b_b_d8b_2c7" },
7-
{ "name": "caffeine-api", "version": "3.2.0-166.v72a_6d74b_870f" },
8-
{ "name": "cloudbees-folder", "version": "6.1012.v79a_86a_1ea_c1f" },
9-
{ "name": "display-url-api", "version": "2.209.v582ed814ff2f" },
10-
{ "name": "durable-task", "version": "587.v84b_877235b_45" },
11-
{ "name": "instance-identity", "version": "201.vd2a_b_5a_468a_a_6" },
12-
{ "name": "ionicons-api", "version": "82.v0597178874e1" },
4+
{ "name": "asm-api", "version": "9.9-185.va_6c6b_3348b_c3" },
5+
{ "name": "bouncycastle-api", "version": "2.30.1.82-277.v70ca_0b_877184" },
6+
{ "name": "branch-api", "version": "2.1259.v45c101731c76" },
7+
{ "name": "caffeine-api", "version": "3.2.3-194.v31a_b_f7a_b_5a_81" },
8+
{ "name": "cloudbees-folder", "version": "6.1073.va_7888eb_dd514" },
9+
{ "name": "commons-lang3-api", "version": "3.19.0-104.v12125f33a_255" },
10+
{ "name": "display-url-api", "version": "2.217.va_6b_de84cc74b_" },
11+
{ "name": "durable-task", "version": "635.v3733cef34b_5e" },
12+
{ "name": "instance-identity", "version": "203.v15e81a_1b_7a_38" },
13+
{ "name": "ionicons-api", "version": "94.vcc3065403257" },
1314
{ "name": "jakarta-activation-api", "version": "2.1.3-2" },
14-
{ "name": "jakarta-mail-api", "version": "2.1.3-2" },
15+
{ "name": "jakarta-mail-api", "version": "2.1.3-3" },
1516
{ "name": "javax-activation-api", "version": "1.2.0-8" },
1617
{ "name": "javax-mail-api", "version": "1.6.2-11" },
17-
{ "name": "mailer", "version": "489.vd4b_25144138f" },
18-
{ "name": "pipeline-groovy-lib", "version": "752.vdddedf804e72" },
19-
{ "name": "scm-api", "version": "704.v3ce5c542825a_" },
20-
{ "name": "script-security", "version": "1373.vb_b_4a_a_c26fa_00" },
21-
{ "name": "structs", "version": "343.vdcf37b_a_c81d5" },
18+
{ "name": "mailer", "version": "522.va_995fa_cfb_8b_d" },
19+
{ "name": "pipeline-groovy-lib", "version": "787.ve2fef0efdca_6" },
20+
{ "name": "scm-api", "version": "712.v8846fdd68c88" },
21+
{ "name": "script-security", "version": "1385.v7d2d9ec4d909" },
22+
{ "name": "structs", "version": "362.va_b_695ef4fdf9" },
2223
{ "name": "variant", "version": "70.va_d9f17f859e0" },
23-
{ "name": "workflow-api", "version": "1371.ve334280b_d611" },
24-
{ "name": "workflow-basic-steps", "version": "1079.vce64b_a_929c5a_" },
25-
{ "name": "workflow-cps", "version": "4046.v90b_1b_9edec67" },
26-
{ "name": "workflow-durable-task-step", "version": "1405.v1fcd4a_d00096" },
27-
{ "name": "workflow-job", "version": "1520.v56d65e3b_4566" },
28-
{ "name": "workflow-multibranch", "version": "806.vb_b_688f609ee9" },
29-
{ "name": "workflow-scm-step", "version": "437.v05a_f66b_e5ef8" },
30-
{ "name": "workflow-step-api", "version": "700.v6e45cb_a_5a_a_21" },
31-
{ "name": "workflow-support", "version": "968.v8f17397e87b_8" }
24+
{ "name": "workflow-api", "version": "1384.vdc05a_48f535f" },
25+
{ "name": "workflow-basic-steps", "version": "1098.v808b_fd7f8cf4" },
26+
{ "name": "workflow-cps", "version": "4218.vff679a_5c0f3a_" },
27+
{ "name": "workflow-durable-task-step", "version": "1464.v2d3f5c68f84c" },
28+
{ "name": "workflow-job", "version": "1559.va_a_533730b_ea_d" },
29+
{ "name": "workflow-multibranch", "version": "821.vc3b_4ea_780798" },
30+
{ "name": "workflow-scm-step", "version": "466.va_d69e602552b_" },
31+
{ "name": "workflow-step-api", "version": "710.v3e456cc85233" },
32+
{ "name": "workflow-support", "version": "1004.veee3a_d67cdb_9" }
3233
]
3334
}

modules/C4B-Environment/C4B-Environment.psm1

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1207,7 +1207,7 @@ The host name of the C4B instance.
12071207
}
12081208

12091209
Copy-Item $PSScriptRoot\ReadmeTemplate.html.j2 -Destination $env:Public\Desktop\Readme.html -Force
1210-
1210+
12111211
# Working around the existing j2 template, so we can keep them roughly in sync
12121212
Invoke-TextReplacementInFile -Path $env:Public\Desktop\Readme.html -Replacement @{
12131213
# CCM Values
@@ -1298,4 +1298,67 @@ if (
12981298
Invoke-Choco feature enable --name='useFipsCompliantChecksums'
12991299
}
13001300

1301+
function Invoke-JenkinsApi {
1302+
<#
1303+
.Synopsis
1304+
Invokes an existing job on a Jenkins server
1305+
.Example
1306+
Invoke-JenkinsApi
1307+
#>
1308+
param(
1309+
# The name of the job to invoke
1310+
[Parameter(Mandatory)]
1311+
[ValidateNotNullOrEmpty()]
1312+
[string]$Slug,
1313+
1314+
# The URI of the Jenkins server, including protocols and port if required
1315+
[ValidateNotNullOrEmpty()]
1316+
[string]$Uri = 'http://localhost:8080/jenkins',
1317+
1318+
[string]$Method = "GET",
1319+
1320+
# The Jenkins credential to authenticate with
1321+
[Parameter(Mandatory)]
1322+
[ValidateNotNullOrEmpty()]
1323+
[System.Management.Automation.PSCredential]
1324+
[System.Management.Automation.CredentialAttribute()]
1325+
$Credential,
1326+
1327+
[switch]$RequiresCrumb
1328+
)
1329+
$RequestParams = @{}
1330+
1331+
$Header = @{}
1332+
$Header['Authorization'] = 'Basic {0}' -f ([Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("$($Credential.UserName):$($Credential.GetNetworkCredential().Password)")))
1333+
$RequestParams['Headers'] = $Header
1334+
1335+
if ($RequiresCrumb) {
1336+
$JenkinsWebSession = New-Object Microsoft.PowerShell.Commands.WebRequestSession
1337+
1338+
$RequestParams['Uri'] = '{0}/crumbIssuer/api/json' -f $Uri
1339+
$RequestParams['Method'] = 'GET'
1340+
1341+
$RequestParams['WebSession'] = $JenkinsWebSession
1342+
1343+
$CrumbResponse = Invoke-RestMethod @RequestParams
1344+
1345+
$Header['Jenkins-Crumb'] = $CrumbResponse.crumb
1346+
$RequestParams['Uri'] = '{0}/me/descriptorByName/jenkins.security.ApiTokenProperty/generateNewToken?newTokenName=GHA' -f $Uri
1347+
$RequestParams['Method'] = 'POST'
1348+
$RequestParams['Headers'] = $Header
1349+
1350+
$Token = (Invoke-RestMethod @RequestParams).data.tokenValue
1351+
$RequestParams.Headers['Authorization'] = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("$($Credential.UserName):$($Token)"))
1352+
}
1353+
1354+
$RequestParams['Uri'] = '{0}/{1}' -f $Uri.TrimEnd('/'), $Slug.TrimStart('/')
1355+
$RequestParams['Method'] = $Method
1356+
1357+
if ($Parameters) {
1358+
$RequestParams['Body'] = $Parameters
1359+
}
1360+
1361+
Invoke-RestMethod @RequestParams
1362+
}
1363+
13011364
Export-ModuleMember -Function "*"

tests/jenkins.tests.ps1

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1+
#requires -Modules C4B-Environment
12
[CmdletBinding()]
2-
Param(
3+
param(
34
[Parameter(Mandatory)]
4-
[String]
5-
$Fqdn
5+
[String]$Fqdn,
6+
7+
[PSCredential]$JenkinsCredential = $(
8+
if (Get-ChocoEnvironmentProperty JenkinsCredential) {
9+
Get-ChocoEnvironmentProperty JenkinsCredential
10+
} else {
11+
Get-Credential -UserName admin -Message "Jenkins Account"
12+
}
13+
)
614
)
715

816
Describe "Jenkins Configuration" {
@@ -12,7 +20,7 @@ Describe "Jenkins Configuration" {
1220
$service = Get-Service jenkins
1321
}
1422

15-
It "Jenkins is installed" {
23+
It "Jenkins package is installed" {
1624
$jenkins | Should -Not -BeNullOrEmpty
1725
}
1826

@@ -23,7 +31,6 @@ Describe "Jenkins Configuration" {
2331
It "Service is running" {
2432
$service.Status | Should -Be 'Running'
2533
}
26-
2734
}
2835

2936
Context "Required Scripts" {
@@ -44,21 +51,17 @@ Describe "Jenkins Configuration" {
4451
}
4552
}
4653

47-
Context "Required Jobs" {
54+
Context "Required Jobs" -Skip:$(-not $JenkinsCredential) {
4855
BeforeAll {
49-
$jobs = (Get-ChildItem 'C:\ProgramData\Jenkins\.jenkins\jobs\' -Directory).Name
50-
}
51-
52-
It "'Internalize packages from the Community Repository' is present" {
53-
'Internalize packages from the Community Repository' -in $jobs | Should -Be $true
56+
$Jobs = (Invoke-JenkinsApi -Uri "https://$($FQDN):7443" -Slug "/api/json" -Credential $JenkinsCredential).jobs
5457
}
5558

56-
It "'Update Production Repository' is present" {
57-
'Update Production Repository' -in $jobs | Should -Be $true
58-
}
59-
60-
It "'Update test repository from Chocolatey Community Repository' is present" {
61-
'Update test repository from Chocolatey Community Repository' -in $jobs | Should -Be $true
59+
It "'<_>' is present" -ForEach @(
60+
'Internalize packages from the Community Repository'
61+
'Update Production Repository'
62+
'Update test repository from Chocolatey Community Repository'
63+
) {
64+
$Jobs.Name | Should -Contain $_
6265
}
6366
}
6467

@@ -68,17 +71,26 @@ Describe "Jenkins Configuration" {
6871
}
6972
}
7073

71-
Context "Required Plugins" {
74+
Context "Required Plugins" -Skip:$(-not $JenkinsCredential) {
7275
BeforeDiscovery {
73-
$ExpectedPlugins = (Get-Content $PSScriptRoot\..\files\jenkins.json | ConvertFrom-Json).plugins.name
76+
$ExpectedPlugins = (Get-Content $PSScriptRoot\..\files\jenkins.json | ConvertFrom-Json).plugins
77+
$InstalledPlugins = (Invoke-JenkinsApi -Uri "https://$($Fqdn):7443" -Slug "/manage/pluginManager/api/json?depth=1" -Credential $JenkinsCredential).plugins
7478
}
7579

7680
BeforeAll {
77-
$plugins = (Get-ChildItem 'C:\ProgramData\Jenkins\.jenkins\plugins\' -Directory).Name
81+
$InstalledPlugins = (Invoke-JenkinsApi -Uri "https://$($Fqdn):7443" -Slug "/manage/pluginManager/api/json?depth=1" -Credential $JenkinsCredential).plugins
82+
}
83+
84+
It "<_.name> plugin is installed" -ForEach $ExpectedPlugins {
85+
$PluginShortName, $PluginVersion = $_.name, $_.version
86+
$InstalledPlugins.Where{
87+
$_.shortName -eq $PluginShortName
88+
}.version | Should -Be $PluginVersion -Because "$($PluginShortName) should have been version '$($PluginVersion)'"
7889
}
7990

80-
It "<_> plugin is installed" -ForEach $ExpectedPlugins {
81-
$_ -in $plugins | Should -be $true
91+
# During our builds, we should check we're not merging outdated plugins - but on customer systems, that may be the case.
92+
It "<_.shortName> is not outdated" -ForEach $InstalledPlugins -Skip:$(-not $env:CI) {
93+
$_.hasUpdate | Should -Be $false -Because "$($_.longName) ('$($_.shortName)') should not have an available update"
8294
}
8395
}
8496
}

0 commit comments

Comments
 (0)