Seems like Jira steps works only in Scripted pipeline. How can I make use of JIRA steps inside Declarative pipeline? I get the error Unsupported map entry expression for CPS transformation when I try defining Jira steps inside pipeline.
stages {
stage('Create JIRA Ticket'){
steps{
script {
def jiraserver = "Demo"
def testIssue = [fields [
project [id: '10101'],
summary: '[Test] Code Scan - $BUILD_NUMBER ',
description: 'Automated Pipeline',
customfield_1000: 'customValue',
issuetype: [id: '10000']]]
response = jiraNewIssue issue: testIssue
echo response.successful.toString()
echo response.data.toString()
jiraAddComment site: 'Demo', idOrKey: 'Test-1', comment: 'Started Unit Tests'
}
}
}
I get the error WorkflowScript: 42: Unsupported map entry expression for CPS transformation in this context # line 42, column 17 project [id: '10101'],
You have several syntax issues on the testIssue parameter definition which causes the Unsupported map entry expression exception.
The issues is that fields and project are dictionary keys and should be followed with :.
In addition if you wish to interpolate the BUILD_NUMBER in the summary use double quotes ("").
The following should work:
def testIssue = [fields: [
project: [id: '10101'],
summary: "[Test] Code Scan - $BUILD_NUMBER",
description: 'Automated Pipeline',
customfield_1000: 'customValue',
issuetype: [id: '10000']]]
Related
I have many pipelines using the same choice parameters so I want to import them from an external file. I tried to do the following:
pipeline {
agent any
parameters {
choice(
name: 'myParameter',
choices: readFile "${WORKSPACE}/properties",
description: 'interesting stuff' )
}
}
But i have this error:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 17: expecting ')', found '' # line 17, column 31.
choices: readFile "${WORKSPACE}/properties",
Any idea or advice on what I can do this?
pipeline {
agent none
stages {
stage ('INSTALL_IMAGE') {
steps {
script {
def command = "env.job_file --testbed-file env.testbed_file --image_file env.image_file --mail_to env.mail_to"
build job: 'PYATS_JOB_EXECUTOR', parameters:
[
string(name: 'branch_name', value: env.branch_name),
string(name: 'pyats_job_args', value: ${command}),
]
}
}
}
}
}
Getting this error: java.lang.NoSuchMethodError: No such DSL method '$' found among steps
job_file testbed_file image_file mail_to branch_name are all string parameters defined in the jenkins pipeline project.
You are receiving this error because of the following line: value: ${command}.
The ${} syntax is used for the groovy String Interpolation, and as the name implies can be used only inside double quoted (single line or multi line) strings.
The following should work:
string(name: 'pyats_job_args', value: "${command}"),
However, because your value is already a parameter you do not need the string interpolation at all, you can just use your command parameter directly:
string(name: 'pyats_job_args', value: command),
This is a much more simple and readable approach.
I'm trying to create dynamic Jenkins job pipeline stages based on an array of values but I can't seem to get the loop functioning as expected, it complains about the syntax I'm using but I can't figure it out, is this a Groovy issue?
Approach
uat_nodes:
- 'node1'
- 'node2'
dsl: |
stage('Update UAT dist') {{
build job: '{key}-{module}-DP-BuildNamedDist-UAT'
}}
def UAT_NODES = {uat_nodes}
UAT_NODES.each { UAT_NODE ->
stage('Deploy code to UAT node: ' . ${{UAT_NODE}}) {{
build job: '{key}-{module}-DP-UAT-Nodes', parameters: [
string(name: 'LIMIT', value: '${{UAT_NODE}}'),
string(name: 'PLAYBOOK', value: '{playbook}')
]
}}
}
Error
WorkflowScript: 8: Ambiguous expression could be either a parameterless closure expression or an isolated open code block;
solution: Add an explicit closure parameter list, e.g. {it -> ...}, or force it to be treated as an open block by giving it a label, e.g. L:{...} # line 8, column 56.
e to UAT node: ' . ${{UAT_NODE}}) {{
As the error states, there is a problem with this piece of code: . ${{UAT_NODE}}
If strings would have a $ method, that would call it with a closure inside a closure, that returns UAT_NODE.
I can only assume, that you want to concat strings here similar to perl or php. This is not how it works in groovy.
Use: "Deploy code to UAT node: ${UAT_NODE}". Note the double quotes "! Single quotes ' won't give you replacement (this is every other string you are using in your code).
I'm trying to pass groovy variable to powershell script inside of jenkins pipeline, all in the same place but i don't know how. i tried different ways without success.
I require this to obtain the name of the person who approved the step of PIPELINE and pass it to powershell, which connects with SQL SERVER
stage('Step1'){
steps{
script{
def approverDEV
approverDEV = input id: 'test', message: 'Hello', ok: 'Proceed?', parameters: [choice(choices: 'apple\npear\norange', description: 'Select a fruit for this build', name: 'FRUIT'), string(defaultValue: '', description: '', name: 'myparam')], submitter: 'user1,user2,group1', submitterParameter: 'APPROVER'
echo "This build was approved by: ${approverDEV['APPROVER']}"
}
}
}
stage('Step2'){
steps{
script{
powershell ('''
# Example echo "${approverDEV['APPROVER']}"
# BUT THIS DOESN'T WORK :(
''')
}
}
}
I expect the output is the name of the approver stored in the variable GROOVY approverDEV
Dagett is correct, use double-quotes around the powershell script, then the variables will be evaluated:
script{
powershell ("""
# Example echo "${approverDEV['APPROVER']}"
# BUT THIS DOESN'T WORK :(
""")
}
Using triple double quotes in Groovy is called 'multi-line GString'. In a GString, variables will be evaluated before creating the actual String.
I have been trying to find a solution for changing build parameters programmatically using jenkins pipeline plugin where i have jenkinsfile with following content:
#!/usr/bin/env groovy
import hudson.model.*
properties(
[
parameters(
[
string(defaultValue: 'win64', description: 'PLATFORM', name: 'PLATFORM'),
string(defaultValue: '12.1.0', description: 'PRODUCT_VERSION', name: 'PRODUCT_VERSION')
]
)
]
)
stage('working with parameters'){
node('master'){
def thr = Thread.currentThread()
def build = thr?.executable
def paramsDef = build.getProperty(ParametersDefinitionProperty.class)
if (paramsDef) {
paramsDef.parameterDefinitions.each{ param ->
if (param.name == 'PLATFORM') {
println("Changing parameter ${param.name} default value was '${param.defaultValue}' to 'osx10'")
param.defaultValue = "osx10"
}
}
}
}
}
But it fails everytime with error as :
groovy.lang.MissingPropertyException: No such property: executable for class: java.lang.Thread
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53)
After searching a lot i could find somewhere that this script needs to run as system groovy script and everywhere they are referring to Groovy plugin but as i am using pipeline project, i am not able to understand how can i force pipeline to execute my scripts as system groovy script.
Please solve my queries as i have left no link on google unopened :(