馃毃 Please review the guidelines for contributing to this repository.
[x] Jenkins version
[x] Plugin version
[x] OS
Jenkins version: 2.173
Plugin: 1.11
OS: Docker image (FROM jenkins/jenkins)
Hi,
I'm facing an issue with preconfigured jobs. I have written in yaml PipelineJob with parameters, but when I'm trying to use/pass them into job, in Jenkins they are missing. I don't really know what's the issue and which part of configuration is failing. Probably Job DSL plugin which I also use is worth to mention here.
Here's a part of my yaml configuration:
```- script: >
pipelineJob('Ansible-connection-test') {
parameters {
stringParam('HOST', 'defaultHost', 'Enter host from Ansible inventory where job should be executed')
}
definition {
cps {
script("""\
pipeline {
agent any
stages {
stage ('Checkout') {
steps {
git url: '[email protected]:myRepo.git', branch: 'master'
}
}
stage ('Deploy') {
steps {
standardAnsibleDeploy([ansiblePlaybook:'tasks/common/listfiles/main.yml', ansibleExtras: '-e host=${HOST}'])
}
}
}
}""".stripIndent())
}
}
}
And here's the result what's being visible in Jenkins:
```pipeline {
agent any
stages {
stage ('Checkout') {
steps {
git url: '[email protected]:szymonpronos/devops.git', branch: 'master'
}
}
stage ('Deploy') {
steps {
standardAnsibleDeploy([ansiblePlaybook:'tasks/common/listfiles/main.yml', ansibleExtras: '-e host='])
}
}
}
}
Did I made something wrong? Any workaround for that? Currently I have to manually correct all pipeline jobs.
Thanks
This looks like a job DSL issue.
Since all JCasC is doing is passing it to Job DSL.
To be honest, I'm not sure. I have copy-pasted the job from yaml and put it into git repo. Then I created simply seed job which is building jobs from .groovy scripts from repo and variable was preserved.
Oh, you're talking about ${HOST}
Your issue could have been more clear.
Please read the section Handling Secrets
it specifically says you have to escape ${variables}
You should escape like this: ^${HOST}
JCasC is just trying to be helpful :laughing:
I don't know how I missed that. I was struggling for 3 days!
Thank you so much!
Struggle no more :laughing:
even the ticket is closed, i leave one comment for escaping since someone will googled here like me.
I use helm chart to deploy the jenkins, so it has another layer to escape for this code. which I end with (\^${computer.jnlpmac})
````
master:
tag: lts
JCasC:
configScripts:
stage-jobs: |
jobs:
- script: >
pipelineJob('test_k8s_slave') {
definition {
cps {
script('''
podTemplate(volumes: [emptyDirVolume(mountPath: '/my-mount')], containers: [
containerTemplate(name: 'jnlp', image: 'jenkins/jnlp-slave:3.35-5-alpine', args: '\^${computer.jnlpmac} \^${computer.name}'),
containerTemplate(name: 'busybox', image: 'busybox', ttyEnabled: true, command: 'cat', livenessProbe: containerLivenessProbe( execArgs: 'uname -a', initialDelaySeconds: 5, timeoutSeconds: 1, failureThreshold: 3, periodSeconds: 10, successThreshold: 1))
]) {
node(POD_LABEL) {
stage('Wait for Liveness Probe') {
container('busybox') {
sh 'sleep 6 && echo "Still alive"'
}
}
}
}
'''.stripIndent())
}
}
}
````
Thank you @larrycai , @jetersen. Would'n be better this another session of docs?
That's helm chart values specific and can be avoided by putting the script inside a groovy file. Which you can fetch using a initContainer. So yes there different ways of doing the same thing.
That's helm chart values specific and can be avoided by putting the script inside a groovy file. Which you can fetch using a initContainer. So yes there different ways of doing the same thing.
Sure. Thanks for the clue!
Most helpful comment
Oh, you're talking about
${HOST}Your issue could have been more clear.
Please read the section Handling Secrets
it specifically says you have to escape
${variables}You should escape like this:
^${HOST}JCasC is just trying to be helpful :laughing: