grep on a shell command in a pipeline scripted script The 2019 Stack Overflow Developer Survey Results Are Inif else bash scriptAbort pipeline build if no new commitsHow to switch the user and to pass the password along in Groovy script?Running a script through jenkinsbranch name in Jenkins regular pipeline jobIs it possible to download and configure jenkins with a script?Unable to execute script on remote host using ssh-plugin - JenkinsJSON on the command line with jq in Jenkinsfind command fails in jenkins, but not in terminalJenkins pipeline: scp tries to copy to other remote, Host key verification failed
How do PCB vias affect signal quality?
Does HR tell a hiring manager about salary negotiations?
Cooking pasta in a water boiler
Output the Arecibo Message
Can a flute soloist sit?
What information about me do stores get via my credit card?
Why don't hard Brexiteers insist on a hard border to prevent illegal immigration after Brexit?
How to charge AirPods to keep battery healthy?
Why didn't the Event Horizon Telescope team mention Sagittarius A*?
Did Scotland spend $250,000 for the slogan "Welcome to Scotland"?
I am an eight letter word. What am I?
Finding the area between two curves with Integrate
Likelihood that a superbug or lethal virus could come from a landfill
Why couldn't they take pictures of a closer black hole?
How did passengers keep warm on sail ships?
Deal with toxic manager when you can't quit
Did the UK government pay "millions and millions of dollars" to try to snag Julian Assange?
"as much details as you can remember"
Does adding complexity mean a more secure cipher?
What to do when moving next to a bird sanctuary with a loosely-domesticated cat?
Can there be female White Walkers?
Is there a way to generate a uniformly distributed point on a sphere from a fixed amount of random real numbers?
Why isn't the circumferential light around the M87 black hole's event horizon symmetric?
Loose spokes after only a few rides
grep on a shell command in a pipeline scripted script
The 2019 Stack Overflow Developer Survey Results Are Inif else bash scriptAbort pipeline build if no new commitsHow to switch the user and to pass the password along in Groovy script?Running a script through jenkinsbranch name in Jenkins regular pipeline jobIs it possible to download and configure jenkins with a script?Unable to execute script on remote host using ssh-plugin - JenkinsJSON on the command line with jq in Jenkinsfind command fails in jenkins, but not in terminalJenkins pipeline: scp tries to copy to other remote, Host key verification failed
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
When I want to make several shell commands my scripted pipeline returns the answer of the first command without executing the pipes.
Here is my case:
I want to get specific content on an HTML page. So I do a curl on the page then a grep and finally an awk.
def checkState(hostUri, check) {
node('master')
def result = sh 'curl -Lsd "login=username&password=password&button=Login" -c cookie $hostUri && grep $check && awk -F '"' 'print $2''
println result
Only the console return of my pipeline corresponds to the execution of the curl command only without executing the grep and awk.
Running on Jenkins in /var/lib/jenkins/workspace/Clearcase@8
[Pipeline]
[Pipeline] sh
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
...
</html>
[Pipeline]
[Pipeline] // node
I have tried different methods such as the use of '''
or the new BuildProcess
command which does not exist in scripted pipeline.
jenkins
New contributor
add a comment |
When I want to make several shell commands my scripted pipeline returns the answer of the first command without executing the pipes.
Here is my case:
I want to get specific content on an HTML page. So I do a curl on the page then a grep and finally an awk.
def checkState(hostUri, check) {
node('master')
def result = sh 'curl -Lsd "login=username&password=password&button=Login" -c cookie $hostUri && grep $check && awk -F '"' 'print $2''
println result
Only the console return of my pipeline corresponds to the execution of the curl command only without executing the grep and awk.
Running on Jenkins in /var/lib/jenkins/workspace/Clearcase@8
[Pipeline]
[Pipeline] sh
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
...
</html>
[Pipeline]
[Pipeline] // node
I have tried different methods such as the use of '''
or the new BuildProcess
command which does not exist in scripted pipeline.
jenkins
New contributor
If you want the output ofcurl
to go togrep
and thenawk
, you should use pipes:curl .. | grep .. | awk
. The&&
operator is used to chain commands (run a command if the previous one succeeds).
– Haxiel
Apr 8 at 12:26
@Haxiel Indeed, the use of pipes seems to work even inside the scripted pipeline. I don't understand it seems to me that I tried this method first, like in a classic unix terminal... Thank you very much it seems to work perfectly.
– GotExx
Apr 8 at 12:33
@GotExx That's great. I'll add that as a proper answer to your question.
– Haxiel
Apr 8 at 12:36
add a comment |
When I want to make several shell commands my scripted pipeline returns the answer of the first command without executing the pipes.
Here is my case:
I want to get specific content on an HTML page. So I do a curl on the page then a grep and finally an awk.
def checkState(hostUri, check) {
node('master')
def result = sh 'curl -Lsd "login=username&password=password&button=Login" -c cookie $hostUri && grep $check && awk -F '"' 'print $2''
println result
Only the console return of my pipeline corresponds to the execution of the curl command only without executing the grep and awk.
Running on Jenkins in /var/lib/jenkins/workspace/Clearcase@8
[Pipeline]
[Pipeline] sh
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
...
</html>
[Pipeline]
[Pipeline] // node
I have tried different methods such as the use of '''
or the new BuildProcess
command which does not exist in scripted pipeline.
jenkins
New contributor
When I want to make several shell commands my scripted pipeline returns the answer of the first command without executing the pipes.
Here is my case:
I want to get specific content on an HTML page. So I do a curl on the page then a grep and finally an awk.
def checkState(hostUri, check) {
node('master')
def result = sh 'curl -Lsd "login=username&password=password&button=Login" -c cookie $hostUri && grep $check && awk -F '"' 'print $2''
println result
Only the console return of my pipeline corresponds to the execution of the curl command only without executing the grep and awk.
Running on Jenkins in /var/lib/jenkins/workspace/Clearcase@8
[Pipeline]
[Pipeline] sh
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
...
</html>
[Pipeline]
[Pipeline] // node
I have tried different methods such as the use of '''
or the new BuildProcess
command which does not exist in scripted pipeline.
jenkins
jenkins
New contributor
New contributor
New contributor
asked Apr 8 at 11:25
GotExxGotExx
114
114
New contributor
New contributor
If you want the output ofcurl
to go togrep
and thenawk
, you should use pipes:curl .. | grep .. | awk
. The&&
operator is used to chain commands (run a command if the previous one succeeds).
– Haxiel
Apr 8 at 12:26
@Haxiel Indeed, the use of pipes seems to work even inside the scripted pipeline. I don't understand it seems to me that I tried this method first, like in a classic unix terminal... Thank you very much it seems to work perfectly.
– GotExx
Apr 8 at 12:33
@GotExx That's great. I'll add that as a proper answer to your question.
– Haxiel
Apr 8 at 12:36
add a comment |
If you want the output ofcurl
to go togrep
and thenawk
, you should use pipes:curl .. | grep .. | awk
. The&&
operator is used to chain commands (run a command if the previous one succeeds).
– Haxiel
Apr 8 at 12:26
@Haxiel Indeed, the use of pipes seems to work even inside the scripted pipeline. I don't understand it seems to me that I tried this method first, like in a classic unix terminal... Thank you very much it seems to work perfectly.
– GotExx
Apr 8 at 12:33
@GotExx That's great. I'll add that as a proper answer to your question.
– Haxiel
Apr 8 at 12:36
If you want the output of
curl
to go to grep
and then awk
, you should use pipes: curl .. | grep .. | awk
. The &&
operator is used to chain commands (run a command if the previous one succeeds).– Haxiel
Apr 8 at 12:26
If you want the output of
curl
to go to grep
and then awk
, you should use pipes: curl .. | grep .. | awk
. The &&
operator is used to chain commands (run a command if the previous one succeeds).– Haxiel
Apr 8 at 12:26
@Haxiel Indeed, the use of pipes seems to work even inside the scripted pipeline. I don't understand it seems to me that I tried this method first, like in a classic unix terminal... Thank you very much it seems to work perfectly.
– GotExx
Apr 8 at 12:33
@Haxiel Indeed, the use of pipes seems to work even inside the scripted pipeline. I don't understand it seems to me that I tried this method first, like in a classic unix terminal... Thank you very much it seems to work perfectly.
– GotExx
Apr 8 at 12:33
@GotExx That's great. I'll add that as a proper answer to your question.
– Haxiel
Apr 8 at 12:36
@GotExx That's great. I'll add that as a proper answer to your question.
– Haxiel
Apr 8 at 12:36
add a comment |
1 Answer
1
active
oldest
votes
In the Jenkinsfile shown, the variable assignment involves a shell step:
def result = sh 'curl -Lsd "login=username&password=password&button=Login" -c cookie $hostUri && grep $check && awk -F '"' 'print $2''
Jenkins would invoke a shell at this point, and pass the following command to it:
curl -Lsd "login=username&password=password&button=Login" -c cookie $hostUri && grep $check && awk -F '"' 'print $2'
The &&
operator denotes an AND-list. In this case, if the curl
command succeeds, then the grep
command is executed and if that succeeds, then the awk
command would be executed. The standard input/output/error streams of these commands are not connected to each other.
Since the intention here is to parse the output of curl
using the grep
and awk
statements, pipes should be used instead of the &&
operator:
def result = sh 'curl -Lsd "login=username&password=password&button=Login" -c cookie $hostUri | grep $check | awk -F '"' 'print $2''
Consider quoting the hostUri
& check
variables as well, in case you end up with special characters in those fields.
One last note: The commands grep $check
& awk -F '"' 'print $2'
are technically incomplete without a filename argument or some sort of input. If you run them as-is from a shell terminal, they would simply remain stuck. However, since Jenkins runs the build process non-interactively, I would assume that their standard input streams are redirected from /dev/null
. In that case, the grep
commands would fail with a non-zero error code.
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
GotExx is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f511211%2fgrep-on-a-shell-command-in-a-pipeline-scripted-script%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
In the Jenkinsfile shown, the variable assignment involves a shell step:
def result = sh 'curl -Lsd "login=username&password=password&button=Login" -c cookie $hostUri && grep $check && awk -F '"' 'print $2''
Jenkins would invoke a shell at this point, and pass the following command to it:
curl -Lsd "login=username&password=password&button=Login" -c cookie $hostUri && grep $check && awk -F '"' 'print $2'
The &&
operator denotes an AND-list. In this case, if the curl
command succeeds, then the grep
command is executed and if that succeeds, then the awk
command would be executed. The standard input/output/error streams of these commands are not connected to each other.
Since the intention here is to parse the output of curl
using the grep
and awk
statements, pipes should be used instead of the &&
operator:
def result = sh 'curl -Lsd "login=username&password=password&button=Login" -c cookie $hostUri | grep $check | awk -F '"' 'print $2''
Consider quoting the hostUri
& check
variables as well, in case you end up with special characters in those fields.
One last note: The commands grep $check
& awk -F '"' 'print $2'
are technically incomplete without a filename argument or some sort of input. If you run them as-is from a shell terminal, they would simply remain stuck. However, since Jenkins runs the build process non-interactively, I would assume that their standard input streams are redirected from /dev/null
. In that case, the grep
commands would fail with a non-zero error code.
add a comment |
In the Jenkinsfile shown, the variable assignment involves a shell step:
def result = sh 'curl -Lsd "login=username&password=password&button=Login" -c cookie $hostUri && grep $check && awk -F '"' 'print $2''
Jenkins would invoke a shell at this point, and pass the following command to it:
curl -Lsd "login=username&password=password&button=Login" -c cookie $hostUri && grep $check && awk -F '"' 'print $2'
The &&
operator denotes an AND-list. In this case, if the curl
command succeeds, then the grep
command is executed and if that succeeds, then the awk
command would be executed. The standard input/output/error streams of these commands are not connected to each other.
Since the intention here is to parse the output of curl
using the grep
and awk
statements, pipes should be used instead of the &&
operator:
def result = sh 'curl -Lsd "login=username&password=password&button=Login" -c cookie $hostUri | grep $check | awk -F '"' 'print $2''
Consider quoting the hostUri
& check
variables as well, in case you end up with special characters in those fields.
One last note: The commands grep $check
& awk -F '"' 'print $2'
are technically incomplete without a filename argument or some sort of input. If you run them as-is from a shell terminal, they would simply remain stuck. However, since Jenkins runs the build process non-interactively, I would assume that their standard input streams are redirected from /dev/null
. In that case, the grep
commands would fail with a non-zero error code.
add a comment |
In the Jenkinsfile shown, the variable assignment involves a shell step:
def result = sh 'curl -Lsd "login=username&password=password&button=Login" -c cookie $hostUri && grep $check && awk -F '"' 'print $2''
Jenkins would invoke a shell at this point, and pass the following command to it:
curl -Lsd "login=username&password=password&button=Login" -c cookie $hostUri && grep $check && awk -F '"' 'print $2'
The &&
operator denotes an AND-list. In this case, if the curl
command succeeds, then the grep
command is executed and if that succeeds, then the awk
command would be executed. The standard input/output/error streams of these commands are not connected to each other.
Since the intention here is to parse the output of curl
using the grep
and awk
statements, pipes should be used instead of the &&
operator:
def result = sh 'curl -Lsd "login=username&password=password&button=Login" -c cookie $hostUri | grep $check | awk -F '"' 'print $2''
Consider quoting the hostUri
& check
variables as well, in case you end up with special characters in those fields.
One last note: The commands grep $check
& awk -F '"' 'print $2'
are technically incomplete without a filename argument or some sort of input. If you run them as-is from a shell terminal, they would simply remain stuck. However, since Jenkins runs the build process non-interactively, I would assume that their standard input streams are redirected from /dev/null
. In that case, the grep
commands would fail with a non-zero error code.
In the Jenkinsfile shown, the variable assignment involves a shell step:
def result = sh 'curl -Lsd "login=username&password=password&button=Login" -c cookie $hostUri && grep $check && awk -F '"' 'print $2''
Jenkins would invoke a shell at this point, and pass the following command to it:
curl -Lsd "login=username&password=password&button=Login" -c cookie $hostUri && grep $check && awk -F '"' 'print $2'
The &&
operator denotes an AND-list. In this case, if the curl
command succeeds, then the grep
command is executed and if that succeeds, then the awk
command would be executed. The standard input/output/error streams of these commands are not connected to each other.
Since the intention here is to parse the output of curl
using the grep
and awk
statements, pipes should be used instead of the &&
operator:
def result = sh 'curl -Lsd "login=username&password=password&button=Login" -c cookie $hostUri | grep $check | awk -F '"' 'print $2''
Consider quoting the hostUri
& check
variables as well, in case you end up with special characters in those fields.
One last note: The commands grep $check
& awk -F '"' 'print $2'
are technically incomplete without a filename argument or some sort of input. If you run them as-is from a shell terminal, they would simply remain stuck. However, since Jenkins runs the build process non-interactively, I would assume that their standard input streams are redirected from /dev/null
. In that case, the grep
commands would fail with a non-zero error code.
edited Apr 8 at 12:59
answered Apr 8 at 12:47
HaxielHaxiel
3,62811021
3,62811021
add a comment |
add a comment |
GotExx is a new contributor. Be nice, and check out our Code of Conduct.
GotExx is a new contributor. Be nice, and check out our Code of Conduct.
GotExx is a new contributor. Be nice, and check out our Code of Conduct.
GotExx is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f511211%2fgrep-on-a-shell-command-in-a-pipeline-scripted-script%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
If you want the output of
curl
to go togrep
and thenawk
, you should use pipes:curl .. | grep .. | awk
. The&&
operator is used to chain commands (run a command if the previous one succeeds).– Haxiel
Apr 8 at 12:26
@Haxiel Indeed, the use of pipes seems to work even inside the scripted pipeline. I don't understand it seems to me that I tried this method first, like in a classic unix terminal... Thank you very much it seems to work perfectly.
– GotExx
Apr 8 at 12:33
@GotExx That's great. I'll add that as a proper answer to your question.
– Haxiel
Apr 8 at 12:36