Skip to content

Commit

Permalink
feat(parallelDockerUpdatecli) allow building Docker images in VMs (je…
Browse files Browse the repository at this point in the history
…nkins-infra#319)

Signed-off-by: Damien Duportal <[email protected]>
  • Loading branch information
dduportal authored and smerle33 committed Jan 16, 2024
1 parent ce10936 commit 1c1aa97
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
11 changes: 11 additions & 0 deletions test/groovy/ParallelDockerUpdatecliStepTests.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ class ParallelDockerUpdatecliStepTests extends BaseTest {

// And the correct image name is passed to buildDockerAndPublishImage
assertTrue(assertMethodCallContainsPattern('buildDockerAndPublishImage', testImageName))
// And the correct settings
assertTrue(assertMethodCallContainsPattern('buildDockerAndPublishImage', 'automaticSemanticVersioning=true'))
assertTrue(assertMethodCallContainsPattern('buildDockerAndPublishImage', 'gitCredentials=github-app-infra'))

// And updatecli(action: 'diff') is called
assertTrue(assertMethodCallContainsPattern('updatecli', 'action=diff'))
Expand Down Expand Up @@ -162,6 +165,9 @@ class ParallelDockerUpdatecliStepTests extends BaseTest {
updatecliConfig: [
containerMemory: anotherContainerMemory,
],
buildDockerConfig: [
useContainer: false,
],
credentialsId: anotherCredentialsId
)
printCallStack()
Expand All @@ -174,6 +180,11 @@ class ParallelDockerUpdatecliStepTests extends BaseTest {

// And the correct image name is passed to buildDockerAndPublishImage
assertTrue(assertMethodCallContainsPattern('buildDockerAndPublishImage', testImageName))
// And the correct fixed settings for buildDockerAndPublishImage
assertTrue(assertMethodCallContainsPattern('buildDockerAndPublishImage', 'automaticSemanticVersioning=true'))
assertTrue(assertMethodCallContainsPattern('buildDockerAndPublishImage', 'gitCredentials=github-app-infra'))
// And the custom settings for buildDockerAndPublishImage
assertTrue(assertMethodCallContainsPattern('buildDockerAndPublishImage', 'useContainer=false'))

// And updatecli(action: 'diff') is called
assertTrue(assertMethodCallContainsPattern('updatecli', 'action=diff'))
Expand Down
8 changes: 4 additions & 4 deletions vars/parallelDockerUpdatecli.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def call(userConfig = [:]) {
credentialsId: 'updatecli-github-token',
updatecliApplyCronTriggerExpression: '@weekly',
updatecliConfig: [:],
buildDockerConfig: [:],
]

if (userConfig.containerMemory) {
Expand All @@ -28,10 +29,9 @@ def call(userConfig = [:]) {
'docker-image': {
// Do not rebuild the image when triggered by a periodic job if the config desactivate them
if (finalConfig.rebuildImageOnPeriodicJob || (!finalConfig.rebuildImageOnPeriodicJob && !currentBuild.getBuildCauses().contains('hudson.triggers.TimerTrigger'))) {
buildDockerAndPublishImage(finalConfig.imageName, [
automaticSemanticVersioning: true,
gitCredentials: 'github-app-infra'
])
// Merging the 2 maps - https://blog.mrhaki.com/2010/04/groovy-goodness-adding-maps-to-map_21.html
final Map dockerBuildConfig = [automaticSemanticVersioning: true, gitCredentials: 'github-app-infra'] << finalConfig.buildDockerConfig
buildDockerAndPublishImage(finalConfig.imageName, dockerBuildConfig)
}
},
'updatecli': {
Expand Down

0 comments on commit 1c1aa97

Please sign in to comment.