Skip to content

Commit

Permalink
revert updatecli changes as in other PR
Browse files Browse the repository at this point in the history
  • Loading branch information
smerle33 committed Jan 16, 2024
1 parent f885cf6 commit acce4ab
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 33 deletions.
15 changes: 11 additions & 4 deletions test/groovy/UpdatecliStepTests.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ class UpdatecliStepTests extends BaseTest {
// Then we expect a successful build
assertJobStatusSuccess()

// And the correct pod agent used
assertTrue(assertMethodCallContainsPattern('node', 'jnlp-linux-arm64'))
// And the correct pod template defined
assertTrue(assertMethodCallContainsPattern('containerTemplate', 'jenkinsciinfra/helmfile:'))
// And the correct default container memory
assertTrue(assertMethodCallContainsPattern('containerTemplate', 'resourceRequestMemory=512Mi'))
assertTrue(assertMethodCallContainsPattern('containerTemplate', 'resourceLimitMemory=512Mi'))

// And the repository checkouted
assertTrue(assertMethodCallContainsPattern('checkout', ''))
Expand Down Expand Up @@ -72,13 +75,17 @@ class UpdatecliStepTests extends BaseTest {
// Then we expect a successful build
assertJobStatusSuccess()


// And the repository checkouted
assertTrue(assertMethodCallContainsPattern('checkout',''))

// And only the default command called with custom config and NO values
assertTrue(assertMethodCallContainsPattern('sh','updatecli diff --config ./ops/config.yml'))
assertFalse(assertMethodCallContainsPattern('sh','--values'))

// And the correct container memory
assertTrue(assertMethodCallContainsPattern('containerTemplate', 'resourceRequestMemory=512Mi'))
assertTrue(assertMethodCallContainsPattern('containerTemplate', 'resourceLimitMemory=512Mi'))
}

@Test
Expand Down Expand Up @@ -106,7 +113,7 @@ class UpdatecliStepTests extends BaseTest {
def script = loadScript(scriptName)

// when calling the "updatecli" function with a custom Docker image
script.call(updatecliAgentLabel: 'jnlp-linux-amd64')
script.call(updatecliDockerImage: 'golang:1.16-alpine')
printCallStack()

// Then we expect a successful build
Expand All @@ -116,7 +123,7 @@ class UpdatecliStepTests extends BaseTest {
assertTrue(assertMethodCallContainsPattern('checkout',''))

// And the correct pod template defined
assertTrue(assertMethodCallContainsPattern('node', 'jnlp-linux-amd64'))
assertTrue(assertMethodCallContainsPattern('containerTemplate', 'golang:1.16-alpine'))

// And only the diff command called with default values
assertTrue(assertMethodCallContainsPattern('sh','updatecli diff --config ./updatecli/updatecli.d --values ./updatecli/values.yaml'))
Expand Down
67 changes: 67 additions & 0 deletions updatecli/updatecli.d/docker-helmfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
name: Bump `docker-helmfile` version

scms:
default:
kind: github
spec:
user: "{{ .github.user }}"
email: "{{ .github.email }}"
owner: "{{ .github.owner }}"
repository: "{{ .github.repository }}"
token: "{{ requiredEnv .github.token }}"
username: "{{ .github.username }}"
branch: "{{ .github.branch }}"

sources:
lastVersion:
kind: githubrelease
name: Get the latest updatecli version
spec:
owner: "jenkins-infra"
repository: "docker-helmfile"
token: "{{ requiredEnv .github.token }}"
username: "{{ .github.username }}"
versionfilter:
kind: semver
transformers:
- trimprefix: v

conditions:
checkIfDockerImageIsPublished:
name: "Check if the Docker Image is published"
kind: dockerimage
spec:
image: "jenkinsciinfra/helmfile"
architecture: amd64

targets:
updateGroovyCode:
name: Update docker-helmfile in groovy code
kind: file
spec:
file: vars/updatecli.groovy
# Please note that the patterns are specified as "block scalars" (>) with the last endline trimmed (-) to avoid tedious escaping of simple quotes
matchpattern: >-
'jenkinsciinfra/helmfile:(.*)'
replacepattern: >-
'jenkinsciinfra/helmfile:{{ source `lastVersion` }}'
scmid: default
updateDoc:
name: Update docker-helmfile in documentation
kind: file
spec:
file: vars/updatecli.txt
matchpattern: jenkinsciinfra/helmfile:(\d+\.\d+\.\d+)\"
replacepattern: jenkinsciinfra/helmfile:{{ source `lastVersion` }}"
scmid: default

actions:
default:
kind: github/pullrequest
title: Bump `docker-helmfile` version to {{ source "lastVersion" }}
scmid: default
spec:
labels:
- dependencies
- jenkinsciinfra/helmfile
71 changes: 43 additions & 28 deletions vars/updatecli.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ def call(userConfig = [:]) {
action: 'diff', // Updatecli subcommand to execute
config: './updatecli/updatecli.d', // Config manifest used by updatecli (can be a file or a directory)
values: './updatecli/values.yaml', // Values file used by updatecli
updatecliAgentLabel: 'jnlp-linux-arm64', // replace updatecliDockerImage
updatecliDockerImage: 'jenkinsciinfra/helmfile:3.0.59', // Container image to use for running updatecli
containerMemory: '512Mi', // When using 'updatecliDockerImage', this is the memory limit+request of the container
cronTriggerExpression: '', // When specified, it enables cron trigger for the calling pipeline
credentialsId: 'github-app-updatecli-on-jenkins-infra', // githubApp or usernamePassword credentials id to use to get an Access Token. The corresponding populated env vars are USERNAME_VALUE & UPDATECLI_GITHUB_TOKEN
]
Expand All @@ -28,31 +29,45 @@ def call(userConfig = [:]) {
properties([pipelineTriggers([cron(finalConfig.cronTriggerExpression)])])
}


node (finalConfig.updatecliAgentLabel) {
final String updatecliRunStage = "Run updatecli: ${finalConfig.action}"
boolean runUpdatecli = true
stage("Check if updatecli folder exists: ${finalConfig.action}") {
checkout scm
if (!fileExists('updatecli/')) {
echo 'WARNING: no updatecli folder.'
runUpdatecli = false
org.jenkinsci.plugins.pipeline.modeldefinition.Utils.markStageSkippedForConditional(updatecliRunStage)
}
}
stage(updatecliRunStage) {
if (runUpdatecli) {
withCredentials([
usernamePassword(
credentialsId: finalConfig.credentialsId,
usernameVariable: 'USERNAME_VALUE', // Setting this variable is mandatory, even if of not used when the credentials is a githubApp one
passwordVariable: 'UPDATECLI_GITHUB_TOKEN'
)
]) {
sh 'updatecli version'
sh updatecliCommand
} // withCredentials
} // if (runUpdateCli)
} // stage
}
// The podTemplate must define only a single container, named `jnlp`
// Ref - https://support.cloudbees.com/hc/en-us/articles/360054642231-Considerations-for-Kubernetes-Clients-Connections-when-using-Kubernetes-Plugin
podTemplate(
containers: [
containerTemplate(
name: 'jnlp',
image: finalConfig.updatecliDockerImage,
resourceRequestCpu: '1',
resourceLimitCpu: '1',
resourceRequestMemory: finalConfig.containerMemory,
resourceLimitMemory: finalConfig.containerMemory,
),
]
) {
node(POD_LABEL) {
final String updatecliRunStage = "Run updatecli: ${finalConfig.action}"
boolean runUpdatecli = true
stage("Check if updatecli folder exists: ${finalConfig.action}") {
checkout scm
if (!fileExists('updatecli/')) {
echo 'WARNING: no updatecli folder.'
runUpdatecli = false
org.jenkinsci.plugins.pipeline.modeldefinition.Utils.markStageSkippedForConditional(updatecliRunStage)
}
}
stage(updatecliRunStage) {
if (runUpdatecli) {
withCredentials([
usernamePassword(
credentialsId: finalConfig.credentialsId,
usernameVariable: 'USERNAME_VALUE', // Setting this variable is mandatory, even if of not used when the credentials is a githubApp one
passwordVariable: 'UPDATECLI_GITHUB_TOKEN'
)
]) {
sh 'updatecli version'
sh updatecliCommand
} // withCredentials
} // if (runUpdateCli)
} // stage
} // node
} // podTemplate
}
3 changes: 2 additions & 1 deletion vars/updatecli.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
<li>String action: (Optional - Default: "diff") Updatecli action (e.g. subcommand) to execute.</li>
<li>String config: (Optional - Default: "./updatecli/updatecli.d") path to the file or directory with the updatecli configuration (flag "--config").</li>
<li>String values: (Optional - Default: "./updatecli/values.yaml") path to the file with the updatecli values (flag "--values").</li>
<li>String updatecliAgentLabel: (Optional - Default: "jnlp-linux-arm64") agent to be used in the process.</li>
<li>String updatecliDockerImage: (Optional - Default: "jenkinsciinfra/helmfile:3.0.59") Docker Image of updatecli to be used in the process.</li>
<li>String cronTriggerExpression: (Optional - Default: "") Enable periodic execution by providing a cron-like expression.</li>
<li>String containerMemory: (Optional - Default: "512Mi") specify the amount of memory dedicated to the updatecli container.</li>
<li>String credentialsId: (Optional - Default: "github-app-updatecli-on-jenkins-infra") specify the githubApp or usernamePassword credentials id to use to get an Access Token. The corresponding populated env vars are USERNAME_VALUE & UPDATECLI_GITHUB_TOKEN</li>
</ul>

Expand Down

0 comments on commit acce4ab

Please sign in to comment.