In a shared library I have this generic pipeline:
sharedlib/vars/agentLauncher.groovy
def launch(Closure body) {
String podLabel = "jenkins-agent-${UUID.randomUUID().toString()}"
String agentImage = 'my-jenkins-agent:latest'
env.agentImage = agentImage
podTemplate(label: podLabel, yaml: libraryResource('agentPodTemplate.yaml')) {
timestamps {
node(podLabel) {
container('my-jenkins-agent') {
//env.agentImage = agentImage
body.call()
}
}
}
}
}
where I am trying to pass the agentImage as a parameter to the podTemplate (located in the same sharedLib) :
sharedlib/resources/agentPodTemplate.yaml
apiVersion: v1
kind: Pod
spec:
containers:
- name: jnlp
image: jenkins/inbound-agent:4.11-1
- name: my-jenkins-agent
image: "${env.agentImage}"
#image: ${agentImage}
#image: ${agentImage}
#image: my-jenkins-agent:latest
command: ['cat']
resources:
limits:
cpu : 1
memory : 4Gi
requests:
cpu: 200m
memory: 1Gi
tty: true
But when I run that from my pipeline in another repo:
Jenkinsfile
@Library(value="sharedlib", changelog=false) _
agentLauncher.launch() {
stage('Checkout') {
checkout scm
}
stage('build') {
container('my-jenkins-agent') {
sh 'whoami'
}
}
}
I get the error:
[Warning][jenkins/jenkins-agent-e9b3e42c-6920-44f4-9a38-caab96a520f8-148zq-rwg3b][Failed] Error: InvalidImageName
[Warning][jenkins/jenkins-agent-e9b3e42c-6920-44f4-9a38-caab96a520f8-148zq-rwg3b][InspectFailed] Failed to apply default image tag "${agentImage}": couldn't parse image reference "${agentImage}": invalid reference format: repository name must be lowercase
so the variable is clearly not expanded/resolved at all.
I have looked at:
Any suggestions on how to make this work?