Not able to run multiline shell command in Jenkins pipeline - shell

I have a shell script where I am running a multiline command to fetch version from our UI.
Command I am using is:
var=$(curl -k myurl| awk something | sed something)
Then I am using the var for further validations.
The above shell is not promoting the correct response. I checked running this in my terminal and command seems fine but this is not working with Jenkins.
Can someone please help me to understand how to solve this issue.
I have gone through multiple posts but no help.

As you mentioned, it is working on your terminal, then it should also work on your Jenkins shell, can you be more brief by sharing the error or difference in response you are getting ,
But anyways as an alternative to this, you can save your shell command in a script file, and execute it using Jenkins.

Related

Replace a specific character in Jenkins shell step

I have a variable $svn_tag in a Jenkins job.
Its value is branches/sprint-77.
I want the output branches-sprint-77, but I didn't get any output.
I tried these two methods:
$svn_tag|tr "/" -
${svn_tag////-}
It is giving output in bash script, but it is not working in the Jenkins job.
What am I doing wrong?
Your first approach does not make sense, not the least because you try to run `$svn_tagĀ“ as a command. Your second approach works for me:
svn_tag=branches/sprint-77
echo ${svn_tag////-}
prints branches-sprint-77.
For the safe side, you could also check your bash version, by doing a
echo bash=$BASH_VERSION
though I don't think that this feature is version-dependent. Mine is 4.4.12(3)-release.
Use code like below
${svn_tag.replaceAll('/', '-')}

Is there a way to run a shell script in jenkins after finding a particular string from the console output?

Hi I am running a jenkins job I want to find a way to run a shell script or batch script after finding a particular string from the console output of jenkins.
I am able to find the string with the help of text finder plugin of jenkins but there is no way to run a shell script after that.
There are many options in the post build actions of jenkins to run a script but it does not allow to keep a check when to run that script. Can someone help me this?

Running shell script with more information

My script get stuck in some point and it doesn't show any error. I would like to know why and where it gets stuck. Is there a possibility to run a script and show me more information what is it running?
I have found -x command to run it in debug mode but I have a lot of scripts which are connected and it doesn't work for me.
With -vvv I have also tried, but somehow it doesn't show more than without it.
Does anyone know another command for that?
Read:
https://tldp.org/LDP/Bash-Beginners-Guide/html/sect_02_03.html
... and this:
https://unix.stackexchange.com/questions/155551/how-to-debug-a-bash-script
... and if that's not enough, look at the gdb-like bash debugger:
http://bashdb.sourceforge.net/
and many moore...

Jenkins skips build shell command

I've made freestyle Jenkins Job. In the configurations I've added Build step execute shell with simple command echo "HELLO WORLD". When I build the job this shell command I think is never executed.I got no HELLO WORLD output there are also no shell errors and such. Can you tell me possible reasons why this is happening.
What kind of shell are you using?
I've had the same kind of problem with tcsh - a command was never executed (not even echoed with the -x option). As it turned out, it was because there was no "newline" character after that command, and with tcsh that seems to be a problem.

Gradle exec task running shell script distracts asking for input

So I'm trying to get input from the user, specifically their password before we run some commands through sudo. While using gradle to execute the shell script it prints out to the console something like
$ > Building > :gradletaskname
But when it asks for a password or other input it is not intuitive because the way gradle writes to the console it looks like the following.
$ > Building > :gradletasknamePassword:
I have tried echoing new lines but it always displays like my example above. I know this might be a silly question but I've been beating my head on this for a while now.
It's a known limitation and will be fixed in one of the next releases. Here's a link to the JIRA issue: http://issues.gradle.org/browse/GRADLE-1147

Resources