Description
I'm hitting a validation error in CircleCI
alexlordthorsen#Alexs-MBP ~/git/data/data-platform [255] :( % circleci config validate
Error: Unable to parse YAML
while scanning a double-quoted scalar
in 'string', line 145, column 20:
default: "${CIRCLE_BRANCH//[\/-]/_}"
^
found unknown escape character /(47)
in 'string', line 145, column 40:
... default: "${CIRCLE_BRANCH//[\/-]/_}"
with this command definition
set-build-variables:
parameters:
mwaa_environment:
type: string
description: The MWAA environment that we want to modify with this jobs package build information.
default: "${MWAA_ENVIRONMENT_NAME}"
git_branch:
type: string
# python and s3 both change / and - to _
default: ${CIRCLE_BRANCH//[\/-]/_}
build_number:
type: string
default: "${CIRCLE_BUILD_NUM}"
on a variable expansion that's working in my local shell (both bash and zsh)
alexlordthorsen#Alexs-MBP ~/git/data/data-platform/tests/integration :)% echo "${CIRCLE_BRANCH//[\/-]/_}"
env_dev_qa
Why is circleCI throwing this error?
The issue was solved by dropping the double quotes around the expansion.
default: "${CIRCLE_BRANCH//[\/-]/_}"
to
default: ${CIRCLE_BRANCH//[\/-]/_}
Related
pipline{
agent any
environment{
GIT_HASH = "${GIT_COMMIT.substring(0, 7)}"
}
parameters{
string(
name: 'bld_ver',
defaultValue: "${env.GIT_HASH}",
description: "enter version"
)
}
In above code from Jenkinsfile, If user is not providing bld version then 7 letters of hash will be used as default value. But it is throwing below error:
script.sh: line 6: ${env.GIT_HASH}: bad substitution
Although If I print it using
echo ${env.GIT_HASH}
It is printing correctly, what could be the issue here. How can I pass default value as env variable?.
when i try to pass current testcase (-Jtestname=${TEST_NAME}
) name along with run jmeter robot keyword getting below error,
JMeterLibException: 'Value returned by JMeter: 1'
Run Jmeter ${jmeter} ${jmxPath} ${logPath} -Jpath=${mdmpath} -Jtestname=${TEST_NAME}
My test case name is "AREA MDM"
As per below log info testcase name is getting assigned against -Jtestname but still getting this exception error,
19:27:46.574 INFO Starting JMeter with following parameters:
- JMeter path: /home/sadha/Documents/apache-jmeter-5.4.1/bin/jmeter.sh
- Test plan path: /home/sadha/Documents/apache-jmeter-5.4.1/bin/BizomWebMDM.jmx
- Log file path: /home/sadha/Documents/apache-jmeter-5.4.1/Output/log.jtl
- Other parameters: -Jpath=../BizomWeb/venv/resources/Excel/MDM/areas.xls -Jtestname=AREA MDM .
subprocess.call input list: ['/home/sadha/Documents/apache-jmeter-5.4.1/bin/jmeter.sh', '-n', '-t', '/home/sadha/Documents/apache-jmeter-5.4.1/bin/BizomWebMDM.jmx', '-l', '/home/sadha/Documents/apache-jmeter-5.4.1/Output/log.jtl', '-Jpath=../BizomWeb/venv/resources/Excel/MDM/areas.xls', '-Jtestname=AREA', 'MDM']
19:27:46.575 FAIL JMeterLibException: 'Value returned by JMeter: 1'
19:27:46.575 DEBUG Traceback (most recent call last):
File "/home/sadha/.local/lib/python3.8/site-packages/JMeterClasses.py", line 41, in runJmeter
JMeterRunner(jmeterPath, testPlanPath, logFilePath, otherParams)
File "/home/sadha/.local/lib/python3.8/site-packages/JMeterClasses.py", line 200, in __init__
jmeterOutput = self.runAndPrintResult()
File "/home/sadha/.local/lib/python3.8/site-packages/JMeterClasses.py", line 234, in runAndPrintResult
raise JMeterLibException("%s %s" % (msg, retValue))
If i pass any dummy string it will work but facing issue ony when i pass current testcase name.
You need to surround your AREA MDM stanza with quotation marks like:
-Jtestname="${TEST_NAME}"
or escape each character which needs to be escaped using backslash like change AREA MDM to AREA\ MDM
More information:
Which characters need to be escaped when using Bash?
How Do I Run JMeter in Non-GUI Mode?
I'm having some issues with a Jenkins Job Builder YAML file which contains an attribute (message-content) with "{}" characters in it:
- job-template:
id: senderjob
name: '{job-prefix}{id}'
command: 'echo "executed with $PARAMETER"'
type: freestyle
properties:
- ownership:
enabled: true
owner: user1
- build-discarder:
num-to-keep: 100
parameters:
- string:
name: PARAMETER
default: 'param'
description: 'default parameter for message.'
# template settings
builders:
- shell: '{command}'
publishers:
- ci-publisher:
override-topic: VirtualTopic.abcd.message
message-type: 'Custom'
message-properties: |
release-name=$PARAMETER
PARAMETER=$PARAMETER
message-content: '{"release-name" : "1.0"}'
The error reported is:
jenkins_jobs.errors.JenkinsJobsException: release-name parameter missing to format {release-name : 1.0}
So it looks like it's trying to expand "release-name" with a parameter.
So I have added it as parameter:
- string:
name: release-name
default: '1.0'
description: 'default parameter for release.'
It still reports the same error. Should I include the parameter somewhere else or escape it ? I couldn't find any YAML escape for "{}" characters though.
Any idea?
You should add the following to the configuration file
[job_builder]
allow_empty_variables = True
Link: https://jenkins-job-builder.readthedocs.io/en/latest/definition.html#job-template-1
I have the following line in my Rails app:
pid = Process.spawn("casperjs #{path_to_file} '#{params[:page][:url]}' '#{Rails.root}/tmp/' --ignore-ssl-errors=yes", :out => pipe_cmd_out, :err => pipe_cmd_out)
If params[:page][:url] contains a single quote, like for example this URL: http://www.degree33surfboards.com/surf-gear/ultimate-9'-epoxy-sand-.html
I get this error:
sh: 1: Syntax error: Unterminated quoted string
How can I avoid that to happen?
Use the argument-list form of Process.spawn instead of trying to quote things for the shell.
Process.spawn(
"casperjs", path_to_file, params[:page][:url],
"#{Rails.root}/tmp/", "--ignore-ssl-errors=yes",
:out => pipe_cmd_out,
:err => pipe_cmd_out
)
In puppet, if define command is > 80 characters, how can I wrap into two line to do it?
exec { 'create_domain':
command => "some command exceed 80 character...........................................................how to do how to do?.......",
}
It's sort of ugly, but if the last character in a string is a \ followed by a newline, then the string is continued on the next line. My sample.pp manifest is below:
exec { 'wrapped_string_example':
command => "/bin/echo 12345678901234567890123456789012345678901234567890\
wrapped > /var/tmp/test.txt";
}
Running this with puppet apply sample.pp gives the following output
$ puppet apply sample.pp
notice: /Stage[main]/Exec[wrapped_string_example]/returns: executed successfully
notice: Finished catalog run in 0.10 seconds
And catting the created file shows the lines have wrapped:
$ cat /var/tmp/test.txt
12345678901234567890123456789012345678901234567890wrapped
See https://github.com/puppetlabs/puppet/blob/9fbb36de/lib/puppet/parser/lexer.rb#L537 (as of Puppet v2.7.0)
Also this is sort of a known issue: http://projects.puppetlabs.com/issues/5022
For big chunks of data, heredocs are the best way of dealing with long lines in Puppet manifests. The /L interpolation option is particularly useful. /L causes \ at the end of a line to remove newlines. For example, the following does what you'd expect, stripping indentation and newlines, including the trailing newline.
sshkey { 'example.com':
ensure => present,
type => 'ssh-rsa',
key => #(KEY/L),
RfrXBrU1T6qMNllnhXsJdaud9yBgWWm6OprdEQ3rpkTvCc9kJKH0k8MNfKxeBiGZVsUn435q\
e83opnamtGBz17gUOrzjfmpRuBaDDGmGGTPcO8Dohwz1zYuir93bJmxkNldjogbjAWPfrX10\
8aoDw26K12sK61lOt6GTdR9yjDPdG4zL5G3ZjXCuDyQ6mzcNHdAPPFRQdlRRyCtG2sQWpWan\
3AlYe6h6bG48thlo6vyNvOD8s9K0YBnwl596DJiNCY6EsxnSAhA3Uf9jeKqlVqqrxhEzHufx\
07iP1nXIXCMUV
|-KEY
target => '/home/user/.ssh/authorized_keys',
}
Or to keep the final newline, leave out the - before the end text:
exec { 'create_domain':
command => #(CMD/L),
/bin/echo 123456789012345678901234567890123456789012345678901234567890123456\
wrapped > /var/tmp/test.txt
| CMD
}
As of Puppet 3.5 you have a couple of options that i have used. Ruby allows you to concat strings over a couple of lines.
string = "line #1"\
"line #2"\
"line #3"
p string # => "line #1line #2line #3"
Another option, as of Puppet 3.5 they have added HereDoc functionality. This will allow you to put the string in a section of a source code file that is treated as if it were a separate file.
$mytext = #(EOT)
This block of text is
visibly separated from
everything around it.
| EOT
The puppet documentation is here: https://docs.puppet.com/puppet/4.9/lang_data_string.html#heredocs
If you really care about the 80cols limit you can always abuse a template to achieve that goal
exec {'VeryLongExec':
command => template("${module}/verylongexec")
}
Then put the actual command in that template file
Credits should go to Jan Vansteenkiste to figure