special characters in password in curl command - jenkins

In my password, there are two special characters are there > and :, when i run curl command it's not working with error:
The system cannot find the file, even i tried escape characters in my password as \> and \:.
Also i did double quotes e.g. curl -u "abc\\sys_account:Tabc>fg:Eh" abc.org
Still I haven't get any luck.
Any help will be much appreciated.
Also it's not working with WithCredentials Pipeline syntax in Jenkins.

Related

How to excape '&' in a sh()-call in jenkins

I want to call curl on a webpage with get parameters from the jenkins-groovy-script via sh:
sh("curl http://example.com/page.cgi?param1=a&param2=b&param3=c")
But the command is split at the '&' and in the output log of jenkins there is something like:
+ param3=c
+ curl http://example.com/page.cgi?param1=a
+ param2=b
Of course the call to the web server only contains the first parameter.
I tried already with different kind of escaping but without success.
How can I make the call including all the parameters?
Just like in the command line, you have to quote it or escape it. Research quoting and escaping in sh shell.
Try:
sh("curl 'http://example.com/page.cgi?param1=a&param2=b&param3=c'")
sh('curl "http://example.com/page.cgi?param1=a&param2=b&param3=c"')
sh("curl http://example.com/page.cgi?param1=a\\&param2=b&param3=c")
sh("curl \"http://example.com/page.cgi?param1=a&param2=b&param3=c\"")
& in shell means to run something in the background, like sleep 10 & wait.

use of inverted commas (" ") in sh command in jenkins file

Hi i am using scp command in jenkinsfile via sh ' '.
My command is:
sh 'sshpass -p "my-password" scp /home/jenkinshome.........'
but it fails and in console output i find that inverted commas (" ") from the command is gone.
I am not sure what is happening there. Is there any othe way to pass my password.
The solution that always works for me is I first create password less authentication between 2 servers where I want to scp. Works like a charm. No need to pass password.

GNU Parallel does not do anything using remote execution

I just need a hint. I am trying to run the following command from the GNU parallel tutorial (GNU Parallel tutorial):
parallel -S $SERVER1,$SERVER2 echo ::: running on more hosts
I replaced $SERVERX with known hosts in my network. If I execute the command I'm getting asked for my password for each server and after that nothing happens anymore. The curser blinks all day long and I do not get any error message.
I tried different servers with the same result.
The verbose mode shows:
ssh $SERVER1 -- exec perl -e #GNU_Parallel\\=split/_/,\\"use_IPC::Open3\\;_use_MIME::Base64\\"\\;eval\\"#GNU_Parallel\\"\\;\\$SIG\{CHLD\}\\=\\"IGNORE\\"\\;my\\$zip\\=\(grep\{-x\\$_\}\\"/usr/local/bin/bzip2\\"\)\[0\]\\|\\|\\"bzip2\\"\\;open3\(\\$in,\\$out,\\"\>\\&STDERR\\",\\$zip,\\"-dc\\"\)\\;if\(my\\$perlpid\\=fork\)\{close\\$in\\;\\$eval\\=join\\"\\",\\<\\$out\>\\;close\\$out\\;\}else\{close\\$out\\;print\\$in\(decode_base64\(join\\"\\",#ARGV\)\)\\;close\\$in\\;exit\\;\}wait\\;eval\\$eval\\;
and Followed by random characters
Something similar appears four times. I guess for the four jobs I started. I'd be very happy for help.
I think you are expected to set up passwordless ssh logins to all the remotes so GNU Parallel can get into them. – Mark Setchell
This was the right suggestion. Setting up key authentication using ssh-keygen and ssh-copy-id did the job! Thank you very much now it works. A short hint in the tutorial would have been great.

How to escape $ in a travis ci encrypted environment variable?

Travis CI's user documentation has a section on how to escape secure environment variables. It seems not to work for the '$' symbol. Is there anything special that needs done for the '$' symbol?
I setup this example. In .travis.yml:
travis encrypt "FAKE_PASSWORD=H3llo\\#Worl\\$d" -a
In my script I echo the variable and get:
fake password is H3llo#Worl
It appears that $d is being replaced with nothing. How can I fix this?
The problem is when running travis encrypt the $ symbol needs to be escaped for the command as well as when the variable is used. With two backslashes \\ it only creates one backslash in the variable and $d is still expanded by bash. Using three backslashes fixes the issue.
travis encrypt "FAKE_PASSWORD=H3llo\\#Worl\\\$d" -a
\\ creates a single backslash and \$ creates a $ symbol that is not expanded by bash. When travis runs the bash command to create that variable looks like
FAKE_PASSWORD=H3llo\\#World\$d
This is what bash expects when using a $ in a variable.

How to pass an argument which starts with $ to ant from cygwin terminal?

I am running an ant command from Cygwin terminal where I am signing my exe.
I am running a command similar to
ant -Dpassword=$abcde
Here $abcde is my password but when I run an echo, it shows the password as blank.
How can I pass $ as part of my argument so ant can process it?
In a Unix shell, the $ sign is used to identify a shell variable. To prevent parameter expansion due to it being treated as a variable, you need to either:
escape it (by prepending a backslash)
or wrap it in single quotes (quoting removes the special meaning of certain characters such as $)
Either of the following should work:
ant -Dpassword=\$abcde
ant -Dpassword='$abcde'
Edit: It seems that ant treats the dollar sign as a special character. Assuming that a backslash can be used by ant for escaping special characters, both the backslash and the dollar character should be passed on to ant by the shell:
ant -Dpassword='\$abcde'

Resources