shell scripting for jenkins











up vote
2
down vote

favorite












My Jenkins environment variable $SVN_URL is http://project/svn/neslrepo/trunk/java_project. I want to extract java_project and store in a variable through my shell script.



I tried:



job_name=(echo $SVN_URL | awk -F "/" '{print $NF}')
echo $job_name.war


I expected the output to be java_project.war, but it didn't work. What am I doing wrong?










share|improve this question









New contributor




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
























    up vote
    2
    down vote

    favorite












    My Jenkins environment variable $SVN_URL is http://project/svn/neslrepo/trunk/java_project. I want to extract java_project and store in a variable through my shell script.



    I tried:



    job_name=(echo $SVN_URL | awk -F "/" '{print $NF}')
    echo $job_name.war


    I expected the output to be java_project.war, but it didn't work. What am I doing wrong?










    share|improve this question









    New contributor




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






















      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      My Jenkins environment variable $SVN_URL is http://project/svn/neslrepo/trunk/java_project. I want to extract java_project and store in a variable through my shell script.



      I tried:



      job_name=(echo $SVN_URL | awk -F "/" '{print $NF}')
      echo $job_name.war


      I expected the output to be java_project.war, but it didn't work. What am I doing wrong?










      share|improve this question









      New contributor




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











      My Jenkins environment variable $SVN_URL is http://project/svn/neslrepo/trunk/java_project. I want to extract java_project and store in a variable through my shell script.



      I tried:



      job_name=(echo $SVN_URL | awk -F "/" '{print $NF}')
      echo $job_name.war


      I expected the output to be java_project.war, but it didn't work. What am I doing wrong?







      shell-script shell






      share|improve this question









      New contributor




      user323573 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




      user323573 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








      edited Nov 30 at 10:47









      terdon

      127k31245421




      127k31245421






      New contributor




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









      asked Nov 30 at 9:35









      user323573

      111




      111




      New contributor




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





      New contributor





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






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






















          4 Answers
          4






          active

          oldest

          votes

















          up vote
          7
          down vote













          The shell already provides some nice tools to do this, no need for an external command:



          $ SVN_URL="http://project/svn/neslrepo/trunk/java_project"
          $ echo ${SVN_URL##*/}
          java_project


          So all you need is:



          job_name=${SVN_URL##*/}.war





          share|improve this answer




























            up vote
            3
            down vote













            It appears that basename can also do this, despite the argument being an HTTP URL instead of a filesystem path.



            echo $(basename "http://project/svn/neslrepo/trunk/java_project/").war
            java_project.war


            Since the man page does not mention HTTP URLs, this is probably an abuse of basename. It seems to be a side effect of the structural similarity between an HTTP URL and a filesystem path. man 3 basename says (emphasis mine):




            The functions dirname() and basename() break a null-terminated
            pathname string into directory and filename components. In the usual
            case, dirname() returns the string up to, but not including, the final
            '/', and basename() returns the component following the final '/'.
            Trailing '/' characters are not counted as part of the pathname.







            share|improve this answer




























              up vote
              2
              down vote













              I tried by below 2 methods and it worked fine



              Method1

              @praveen_linux_example ~]# SVN_URL=http://project/svn/neslrepo/trunk/java_project
              [root@praveen_linux_example ~]# jobname=`echo $SVN_URL| awk -F "/" '{print $NF}'`
              [root@praveen_linux_example ~]# echo $jobname.war
              java_project.war
              ======================================================================================================
              Method 2

              SVN_URL=http://project/svn/neslrepo/trunk/java_project
              @praveen_linux_example ~]# echo $SVN_URL| sed "s/.*///"| sed "s/$/.war/"
              java_project.war





              share|improve this answer






























                up vote
                1
                down vote













                The problem is in your job_name=(echo $SVN_URL | awk -F "/" '{print $NF}') line.



                You are trying to use command substitution, however, you've forgotten the $.



                It should be the following in order to make bash execute the commands in brackets:



                job_name=$(echo $SVN_URL | awk -F "/" '{print $NF}')


                The following snippet worked perfectly for me:



                #!/bin/bash

                SVN_URL="http://project/svn/neslrepo/trunk/java_project"

                job_name=$(echo $SVN_URL | awk -F '/' '{print $NF}')
                echo $job_name.war





                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',
                  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
                  });


                  }
                  });






                  user323573 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%2f485103%2fshell-scripting-for-jenkins%23new-answer', 'question_page');
                  }
                  );

                  Post as a guest















                  Required, but never shown

























                  4 Answers
                  4






                  active

                  oldest

                  votes








                  4 Answers
                  4






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes








                  up vote
                  7
                  down vote













                  The shell already provides some nice tools to do this, no need for an external command:



                  $ SVN_URL="http://project/svn/neslrepo/trunk/java_project"
                  $ echo ${SVN_URL##*/}
                  java_project


                  So all you need is:



                  job_name=${SVN_URL##*/}.war





                  share|improve this answer

























                    up vote
                    7
                    down vote













                    The shell already provides some nice tools to do this, no need for an external command:



                    $ SVN_URL="http://project/svn/neslrepo/trunk/java_project"
                    $ echo ${SVN_URL##*/}
                    java_project


                    So all you need is:



                    job_name=${SVN_URL##*/}.war





                    share|improve this answer























                      up vote
                      7
                      down vote










                      up vote
                      7
                      down vote









                      The shell already provides some nice tools to do this, no need for an external command:



                      $ SVN_URL="http://project/svn/neslrepo/trunk/java_project"
                      $ echo ${SVN_URL##*/}
                      java_project


                      So all you need is:



                      job_name=${SVN_URL##*/}.war





                      share|improve this answer












                      The shell already provides some nice tools to do this, no need for an external command:



                      $ SVN_URL="http://project/svn/neslrepo/trunk/java_project"
                      $ echo ${SVN_URL##*/}
                      java_project


                      So all you need is:



                      job_name=${SVN_URL##*/}.war






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Nov 30 at 10:49









                      terdon

                      127k31245421




                      127k31245421
























                          up vote
                          3
                          down vote













                          It appears that basename can also do this, despite the argument being an HTTP URL instead of a filesystem path.



                          echo $(basename "http://project/svn/neslrepo/trunk/java_project/").war
                          java_project.war


                          Since the man page does not mention HTTP URLs, this is probably an abuse of basename. It seems to be a side effect of the structural similarity between an HTTP URL and a filesystem path. man 3 basename says (emphasis mine):




                          The functions dirname() and basename() break a null-terminated
                          pathname string into directory and filename components. In the usual
                          case, dirname() returns the string up to, but not including, the final
                          '/', and basename() returns the component following the final '/'.
                          Trailing '/' characters are not counted as part of the pathname.







                          share|improve this answer

























                            up vote
                            3
                            down vote













                            It appears that basename can also do this, despite the argument being an HTTP URL instead of a filesystem path.



                            echo $(basename "http://project/svn/neslrepo/trunk/java_project/").war
                            java_project.war


                            Since the man page does not mention HTTP URLs, this is probably an abuse of basename. It seems to be a side effect of the structural similarity between an HTTP URL and a filesystem path. man 3 basename says (emphasis mine):




                            The functions dirname() and basename() break a null-terminated
                            pathname string into directory and filename components. In the usual
                            case, dirname() returns the string up to, but not including, the final
                            '/', and basename() returns the component following the final '/'.
                            Trailing '/' characters are not counted as part of the pathname.







                            share|improve this answer























                              up vote
                              3
                              down vote










                              up vote
                              3
                              down vote









                              It appears that basename can also do this, despite the argument being an HTTP URL instead of a filesystem path.



                              echo $(basename "http://project/svn/neslrepo/trunk/java_project/").war
                              java_project.war


                              Since the man page does not mention HTTP URLs, this is probably an abuse of basename. It seems to be a side effect of the structural similarity between an HTTP URL and a filesystem path. man 3 basename says (emphasis mine):




                              The functions dirname() and basename() break a null-terminated
                              pathname string into directory and filename components. In the usual
                              case, dirname() returns the string up to, but not including, the final
                              '/', and basename() returns the component following the final '/'.
                              Trailing '/' characters are not counted as part of the pathname.







                              share|improve this answer












                              It appears that basename can also do this, despite the argument being an HTTP URL instead of a filesystem path.



                              echo $(basename "http://project/svn/neslrepo/trunk/java_project/").war
                              java_project.war


                              Since the man page does not mention HTTP URLs, this is probably an abuse of basename. It seems to be a side effect of the structural similarity between an HTTP URL and a filesystem path. man 3 basename says (emphasis mine):




                              The functions dirname() and basename() break a null-terminated
                              pathname string into directory and filename components. In the usual
                              case, dirname() returns the string up to, but not including, the final
                              '/', and basename() returns the component following the final '/'.
                              Trailing '/' characters are not counted as part of the pathname.








                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Nov 30 at 13:50









                              Haxiel

                              696310




                              696310






















                                  up vote
                                  2
                                  down vote













                                  I tried by below 2 methods and it worked fine



                                  Method1

                                  @praveen_linux_example ~]# SVN_URL=http://project/svn/neslrepo/trunk/java_project
                                  [root@praveen_linux_example ~]# jobname=`echo $SVN_URL| awk -F "/" '{print $NF}'`
                                  [root@praveen_linux_example ~]# echo $jobname.war
                                  java_project.war
                                  ======================================================================================================
                                  Method 2

                                  SVN_URL=http://project/svn/neslrepo/trunk/java_project
                                  @praveen_linux_example ~]# echo $SVN_URL| sed "s/.*///"| sed "s/$/.war/"
                                  java_project.war





                                  share|improve this answer



























                                    up vote
                                    2
                                    down vote













                                    I tried by below 2 methods and it worked fine



                                    Method1

                                    @praveen_linux_example ~]# SVN_URL=http://project/svn/neslrepo/trunk/java_project
                                    [root@praveen_linux_example ~]# jobname=`echo $SVN_URL| awk -F "/" '{print $NF}'`
                                    [root@praveen_linux_example ~]# echo $jobname.war
                                    java_project.war
                                    ======================================================================================================
                                    Method 2

                                    SVN_URL=http://project/svn/neslrepo/trunk/java_project
                                    @praveen_linux_example ~]# echo $SVN_URL| sed "s/.*///"| sed "s/$/.war/"
                                    java_project.war





                                    share|improve this answer

























                                      up vote
                                      2
                                      down vote










                                      up vote
                                      2
                                      down vote









                                      I tried by below 2 methods and it worked fine



                                      Method1

                                      @praveen_linux_example ~]# SVN_URL=http://project/svn/neslrepo/trunk/java_project
                                      [root@praveen_linux_example ~]# jobname=`echo $SVN_URL| awk -F "/" '{print $NF}'`
                                      [root@praveen_linux_example ~]# echo $jobname.war
                                      java_project.war
                                      ======================================================================================================
                                      Method 2

                                      SVN_URL=http://project/svn/neslrepo/trunk/java_project
                                      @praveen_linux_example ~]# echo $SVN_URL| sed "s/.*///"| sed "s/$/.war/"
                                      java_project.war





                                      share|improve this answer














                                      I tried by below 2 methods and it worked fine



                                      Method1

                                      @praveen_linux_example ~]# SVN_URL=http://project/svn/neslrepo/trunk/java_project
                                      [root@praveen_linux_example ~]# jobname=`echo $SVN_URL| awk -F "/" '{print $NF}'`
                                      [root@praveen_linux_example ~]# echo $jobname.war
                                      java_project.war
                                      ======================================================================================================
                                      Method 2

                                      SVN_URL=http://project/svn/neslrepo/trunk/java_project
                                      @praveen_linux_example ~]# echo $SVN_URL| sed "s/.*///"| sed "s/$/.war/"
                                      java_project.war






                                      share|improve this answer














                                      share|improve this answer



                                      share|improve this answer








                                      edited Nov 30 at 18:53









                                      terdon

                                      127k31245421




                                      127k31245421










                                      answered Nov 30 at 15:19









                                      Praveen Kumar BS

                                      1,166138




                                      1,166138






















                                          up vote
                                          1
                                          down vote













                                          The problem is in your job_name=(echo $SVN_URL | awk -F "/" '{print $NF}') line.



                                          You are trying to use command substitution, however, you've forgotten the $.



                                          It should be the following in order to make bash execute the commands in brackets:



                                          job_name=$(echo $SVN_URL | awk -F "/" '{print $NF}')


                                          The following snippet worked perfectly for me:



                                          #!/bin/bash

                                          SVN_URL="http://project/svn/neslrepo/trunk/java_project"

                                          job_name=$(echo $SVN_URL | awk -F '/' '{print $NF}')
                                          echo $job_name.war





                                          share|improve this answer

























                                            up vote
                                            1
                                            down vote













                                            The problem is in your job_name=(echo $SVN_URL | awk -F "/" '{print $NF}') line.



                                            You are trying to use command substitution, however, you've forgotten the $.



                                            It should be the following in order to make bash execute the commands in brackets:



                                            job_name=$(echo $SVN_URL | awk -F "/" '{print $NF}')


                                            The following snippet worked perfectly for me:



                                            #!/bin/bash

                                            SVN_URL="http://project/svn/neslrepo/trunk/java_project"

                                            job_name=$(echo $SVN_URL | awk -F '/' '{print $NF}')
                                            echo $job_name.war





                                            share|improve this answer























                                              up vote
                                              1
                                              down vote










                                              up vote
                                              1
                                              down vote









                                              The problem is in your job_name=(echo $SVN_URL | awk -F "/" '{print $NF}') line.



                                              You are trying to use command substitution, however, you've forgotten the $.



                                              It should be the following in order to make bash execute the commands in brackets:



                                              job_name=$(echo $SVN_URL | awk -F "/" '{print $NF}')


                                              The following snippet worked perfectly for me:



                                              #!/bin/bash

                                              SVN_URL="http://project/svn/neslrepo/trunk/java_project"

                                              job_name=$(echo $SVN_URL | awk -F '/' '{print $NF}')
                                              echo $job_name.war





                                              share|improve this answer












                                              The problem is in your job_name=(echo $SVN_URL | awk -F "/" '{print $NF}') line.



                                              You are trying to use command substitution, however, you've forgotten the $.



                                              It should be the following in order to make bash execute the commands in brackets:



                                              job_name=$(echo $SVN_URL | awk -F "/" '{print $NF}')


                                              The following snippet worked perfectly for me:



                                              #!/bin/bash

                                              SVN_URL="http://project/svn/neslrepo/trunk/java_project"

                                              job_name=$(echo $SVN_URL | awk -F '/' '{print $NF}')
                                              echo $job_name.war






                                              share|improve this answer












                                              share|improve this answer



                                              share|improve this answer










                                              answered Nov 30 at 9:55









                                              Fanatique

                                              12810




                                              12810






















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










                                                  draft saved

                                                  draft discarded


















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













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












                                                  user323573 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.





                                                  Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                                  Please pay close attention to the following guidance:


                                                  • 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%2f485103%2fshell-scripting-for-jenkins%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

                                                  Plaza Victoria

                                                  Puebla de Zaragoza

                                                  Musa