diff --git a/11/nanoserver-1809/Dockerfile b/11/nanoserver-1809/Dockerfile index f7d243b2..66441e3e 100644 --- a/11/nanoserver-1809/Dockerfile +++ b/11/nanoserver-1809/Dockerfile @@ -22,7 +22,7 @@ # THE SOFTWARE. ARG VERSION=4.3-4 -FROM jenkins/agent:${VERSION}-nanoserver-1809-jdk11 +FROM jenkins/agent:${VERSION}-jdk11-nanoserver-1809 ARG VERSION LABEL Description="This is a base image, which allows connecting Jenkins agents via JNLP protocols on Windows" Vendor="Jenkins Project" Version="$VERSION" diff --git a/11/windowsservercore-1809/Dockerfile b/11/windowsservercore-1809/Dockerfile index 700c4429..32e1926e 100644 --- a/11/windowsservercore-1809/Dockerfile +++ b/11/windowsservercore-1809/Dockerfile @@ -22,7 +22,7 @@ # THE SOFTWARE. ARG VERSION=4.3-4 -FROM jenkins/agent:${VERSION}-windowsservercore-1809-jdk11 +FROM jenkins/agent:${VERSION}-jdk11-windowsservercore-1809 LABEL Description="This is a base image, which allows connecting Jenkins agents via JNLP protocols on Windows" Vendor="Jenkins Project" Version="$VERSION" diff --git a/Jenkinsfile b/Jenkinsfile index 7f958ba3..99697c26 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -29,7 +29,6 @@ pipeline { } steps { script { - powershell '& ./make.ps1 build' powershell '& ./make.ps1 test' def branchName = "${env.BRANCH_NAME}" @@ -41,15 +40,11 @@ pipeline { } } - if (env.TAG_NAME != null) { - def tagItems = env.TAG_NAME.split('-') - if(tagItems.length == 2) { - def remotingVersion = tagItems[0] - def buildNumber = tagItems[1] - // we need to build and publish the tag version - infra.withDockerCredentials { - powershell "& ./make.ps1 -PushVersions -RemotingVersion $remotingVersion -BuildNumber $buildNumber publish" - } + def tagName = "${env.TAG_NAME}" + if(tagName ==~ '\\d\\.\\d') { + // we need to build and publish the tagged version + infra.withDockerCredentials { + powershell "& ./make.ps1 -PushVersions -VersionTag $tagName publish" } } @@ -64,9 +59,9 @@ pipeline { options { timeout(time: 30, unit: 'MINUTES') } - steps { + steps { script { - if(!infra.isTrusted()) { + if(!infra.isTrusted()) { deleteDir() checkout scm sh ''' diff --git a/make.ps1 b/make.ps1 index 476cae92..79450af9 100644 --- a/make.ps1 +++ b/make.ps1 @@ -4,8 +4,7 @@ Param( [String] $Target = "build", [String] $AdditionalArgs = '', [String] $Build = '', - [String] $RemotingVersion = '4.3', - [String] $BuildNumber = "1", + [String] $VersionTag = '4.3-2', [switch] $PushVersions = $false ) @@ -23,19 +22,19 @@ if(![String]::IsNullOrWhiteSpace($env:DOCKERHUB_ORGANISATION)) { $builds = @{ 'jdk8' = @{ 'Folder' = '8\windowsservercore-1809'; - 'Tags' = @( "windowsservercore-1809", "windowsservercore-1809-jdk8" ); + 'Tags' = @( "windowsservercore-1809", "jdk8-windowsservercore-1809-jdk8" ); }; 'jdk11' = @{ 'Folder' = '11\windowsservercore-1809'; - 'Tags' = @( "windowsservercore-1809-jdk11" ); + 'Tags' = @( "jdk11-windowsservercore-1809" ); }; 'nanoserver' = @{ 'Folder' = '8\nanoserver-1809'; - 'Tags' = @( "nanoserver-1809", "nanoserver-1809-jdk8" ); + 'Tags' = @( "nanoserver-1809", "jdk8-nanoserver-1809" ); }; 'nanoserver-jdk11' = @{ 'Folder' = '11\nanoserver-1809'; - 'Tags' = @( "nanoserver-1809-jdk11" ); + 'Tags' = @( "jdk11-nanoserver-1809" ); }; } @@ -43,16 +42,16 @@ if(![System.String]::IsNullOrWhiteSpace($Build) -and $builds.ContainsKey($Build) foreach($tag in $builds[$Build]['Tags']) { Copy-Item -Path 'jenkins-agent.ps1' -Destination (Join-Path $builds[$Build]['Folder'] 'jenkins-agent.ps1') -Force Write-Host "Building $Build => tag=$tag" - $cmd = "docker build --build-arg VERSION='$RemotingVersion-$BuildNumber' -t {0}/{1}:{2} {3} {4}" -f $Organization, $Repository, $tag, $AdditionalArgs, $builds[$Build]['Folder'] + $cmd = "docker build -t {0}/{1}:{2} {3} {4}" -f $Organization, $Repository, $tag, $AdditionalArgs, $builds[$Build]['Folder'] Invoke-Expression $cmd if($PushVersions) { - $buildTag = "$RemotingVersion-$BuildNumber-$tag" + $buildTag = "$VersionTag-$tag" if($tag -eq 'latest') { - $buildTag = "$RemotingVersion-$BuildNumber" + $buildTag = "$VersionTag" } Write-Host "Building $Build => tag=$buildTag" - $cmd = "docker build --build-arg VERSION='$RemotingVersion-$BuildNumber' -t {0}/{1}:{2} {3} {4}" -f $Organization, $Repository, $buildTag, $AdditionalArgs, $builds[$Build]['Folder'] + $cmd = "docker build -t {0}/{1}:{2} {3} {4}" -f $Organization, $Repository, $buildTag, $AdditionalArgs, $builds[$Build]['Folder'] Invoke-Expression $cmd } } @@ -61,16 +60,16 @@ if(![System.String]::IsNullOrWhiteSpace($Build) -and $builds.ContainsKey($Build) Copy-Item -Path 'jenkins-agent.ps1' -Destination (Join-Path $builds[$b]['Folder'] 'jenkins-agent.ps1') -Force foreach($tag in $builds[$b]['Tags']) { Write-Host "Building $b => tag=$tag" - $cmd = "docker build --build-arg VERSION='$RemotingVersion-$BuildNumber' -t {0}/{1}:{2} {3} {4}" -f $Organization, $Repository, $tag, $AdditionalArgs, $builds[$b]['Folder'] + $cmd = "docker build -t {0}/{1}:{2} {3} {4}" -f $Organization, $Repository, $tag, $AdditionalArgs, $builds[$b]['Folder'] Invoke-Expression $cmd if($PushVersions) { - $buildTag = "$RemotingVersion-$BuildNumber-$tag" + $buildTag = "$VersionTag-$tag" if($tag -eq 'latest') { - $buildTag = "$RemotingVersion-$BuildNumber" + $buildTag = "$VersionTag" } Write-Host "Building $Build => tag=$buildTag" - $cmd = "docker build --build-arg VERSION='$RemotingVersion-$BuildNumber' -t {0}/{1}:{2} {3} {4}" -f $Organization, $Repository, $buildTag, $AdditionalArgs, $builds[$b]['Folder'] + $cmd = "docker build -t {0}/{1}:{2} {3} {4}" -f $Organization, $Repository, $buildTag, $AdditionalArgs, $builds[$b]['Folder'] Invoke-Expression $cmd } } @@ -89,7 +88,7 @@ if($Target -eq "test") { icacls $module /reset icacls $module /grant Administrators:'F' /inheritance:d /T Remove-Item -Path $module -Recurse -Force -Confirm:$false - Install-Module -Force -Name Pester -RequiredVersion 4.9.0 + Install-Module -Force -Name Pester -MinimumVersion 4.9.0 } if(![System.String]::IsNullOrWhiteSpace($Build) -and $builds.ContainsKey($Build)) { @@ -97,14 +96,12 @@ if($Target -eq "test") { $env:VERSION = "$RemotingVersion-$BuildNumber" Invoke-Pester -Path tests -EnableExit Remove-Item env:\FOLDER - Remove-Item env:\VERSION } else { foreach($b in $builds.Keys) { $env:FOLDER = $builds[$b]['Folder'] $env:VERSION = "$RemotingVersion-$BuildNumber" Invoke-Pester -Path tests -EnableExit Remove-Item env:\FOLDER - Remove-Item env:\VERSION } } } @@ -117,9 +114,9 @@ if($Target -eq "publish") { Invoke-Expression $cmd if($PushVersions) { - $buildTag = "$RemotingVersion-$BuildNumber-$tag" + $buildTag = "$VersionTag-$tag" if($tag -eq 'latest') { - $buildTag = "$RemotingVersion-$BuildNumber" + $buildTag = "$VersionTag" } Write-Host "Publishing $Build => tag=$buildTag" $cmd = "docker push {0}/{1}:{2}" -f $Organization, $Repository, $buildTag @@ -134,9 +131,9 @@ if($Target -eq "publish") { Invoke-Expression $cmd if($PushVersions) { - $buildTag = "$RemotingVersion-$BuildNumber-$tag" + $buildTag = "$VersionTag-$tag" if($tag -eq 'latest') { - $buildTag = "$RemotingVersion-$BuildNumber" + $buildTag = "$VersionTag" } Write-Host "Publishing $Build => tag=$buildTag" $cmd = "docker push {0}/{1}:{2}" -f $Organization, $Repository, $buildTag diff --git a/tests/jnlpAgent.Tests.ps1 b/tests/jnlpAgent.Tests.ps1 index 2d2df49d..94b78ee4 100644 --- a/tests/jnlpAgent.Tests.ps1 +++ b/tests/jnlpAgent.Tests.ps1 @@ -5,7 +5,6 @@ $AGENT_CONTAINER='pester-jenkins-inbound-agent' $SHELL="powershell.exe" $FOLDER = Get-EnvOrDefault 'FOLDER' '' -$VERSION = Get-EnvOrDefault 'VERSION' '4.3-4' $REAL_FOLDER=Resolve-Path -Path "$PSScriptRoot/../${FOLDER}" @@ -42,7 +41,7 @@ Describe "[$JDK $FLAVOR] build image" { } It 'builds image' { - $exitCode, $stdout, $stderr = Run-Program 'docker.exe' "build --build-arg VERSION=$VERSION -t $AGENT_IMAGE $FOLDER" + $exitCode, $stdout, $stderr = Run-Program 'docker.exe' "build -t $AGENT_IMAGE $FOLDER" $exitCode | Should -Be 0 } @@ -53,7 +52,7 @@ Describe "[$JDK $FLAVOR] build image" { Describe "[$JDK $FLAVOR] image has jenkins-agent.ps1 in the correct location" { BeforeAll { - & docker run -d -it --name "$AGENT_CONTAINER" -P "$AGENT_IMAGE" $SHELL + & docker run -dit --name "$AGENT_CONTAINER" -P "$AGENT_IMAGE" $SHELL Is-ContainerRunning $AGENT_CONTAINER | Should -BeTrue } @@ -105,11 +104,11 @@ Describe "[$JDK $FLAVOR] build args" { Push-Location -StackName 'agent' -Path "$PSScriptRoot/.." } - It 'uses build args correctly' { + It -Skip 'uses build args correctly' { $TEST_VERSION="4.3" $TEST_USER="foo" - $exitCode, $stdout, $stderr = Run-Program 'docker.exe' "build --build-arg VERSION=${TEST_VERSION}-1 --build-arg user=$TEST_USER -t $AGENT_IMAGE $FOLDER" + $exitCode, $stdout, $stderr = Run-Program 'docker.exe' "build --build-arg VERSION=${TEST_VERSION}-2 --build-arg user=$TEST_USER -t $AGENT_IMAGE $FOLDER" $exitCode | Should -Be 0 $exitCode, $stdout, $stderr = Run-Program 'docker.exe' "run -dit --name $AGENT_CONTAINER -P $AGENT_IMAGE $SHELL"