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;








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.










share|improve this question







New contributor




GotExx is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • 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











  • @GotExx That's great. I'll add that as a proper answer to your question.

    – Haxiel
    Apr 8 at 12:36

















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.










share|improve this question







New contributor




GotExx is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • 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











  • @GotExx That's great. I'll add that as a proper answer to your question.

    – Haxiel
    Apr 8 at 12:36













0












0








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.










share|improve this question







New contributor




GotExx is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












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






share|improve this question







New contributor




GotExx is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




GotExx is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




GotExx is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Apr 8 at 11:25









GotExxGotExx

114




114




New contributor




GotExx is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





GotExx is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






GotExx is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • 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











  • @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











  • @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










1 Answer
1






active

oldest

votes


















1














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.






share|improve this answer

























    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.









    draft saved

    draft discarded


















    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









    1














    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.






    share|improve this answer





























      1














      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.






      share|improve this answer



























        1












        1








        1







        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.






        share|improve this answer















        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.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Apr 8 at 12:59

























        answered Apr 8 at 12:47









        HaxielHaxiel

        3,62811021




        3,62811021




















            GotExx is a new contributor. Be nice, and check out our Code of Conduct.









            draft saved

            draft discarded


















            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            getting Checkpoint VPN SSL Network Extender working in the command lineHow to connect to CheckPoint VPN on Ubuntu 18.04LTS?Will the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayVPN SSL Network Extender in FirefoxLinux Checkpoint SNX tool configuration issuesCheck Point - Connect under Linux - snx + OTPSNX VPN Ububuntu 18.XXUsing Checkpoint VPN SSL Network Extender CLI with certificateVPN with network manager (nm-applet) is not workingWill the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayImport VPN config files to NetworkManager from command lineTrouble connecting to VPN using network-manager, while command line worksStart a VPN connection with PPTP protocol on command linestarting a docker service daemon breaks the vpn networkCan't connect to vpn with Network-managerVPN SSL Network Extender in FirefoxUsing Checkpoint VPN SSL Network Extender CLI with certificate

            Cannot Extend partition with GParted The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Community Moderator Election ResultsCan't increase partition size with GParted?GParted doesn't recognize the unallocated space after my current partitionWhat is the best way to add unallocated space located before to Ubuntu 12.04 partition with GParted live?I can't figure out how to extend my Arch home partition into free spaceGparted Linux Mint 18.1 issueTrying to extend but swap partition is showing as Unknown in Gparted, shows proper from fdiskRearrange partitions in gparted to extend a partitionUnable to extend partition even though unallocated space is next to it using GPartedAllocate free space to root partitiongparted: how to merge unallocated space with a partition

            Marilyn Monroe Ny fiainany manokana | Jereo koa | Meny fitetezanafanitarana azy.