How do I get the last commit programmatically in Java code? Jenkins / sbt











up vote
-1
down vote

favorite












I started writing a little tool that basically can do something (ex. compile or test code) and then send an email if it fails.



https://github.com/JohnReedLOL/EmailTestingBot



I want to add a feature where this tool can programmatically look at the last commit in the working directory, look at the author of the commit, extract their email, and then email that person whether their commit resulted in a pass or a failure.



For example, I want it to do something like: Git: See my last commit



Where the email basically says:



Subject: Test Results



Message: All your tests passed in dev for commit 0e39756383662573.



Does Jenkins provide this functionality already? I want to make my setup email the person who put in the most recent commit.



Also, is there a way I can obtain the email of the author of the most recent commit programmatically (ex. perhaps with http://www.eclipse.org/jgit/ or http://javagit.sourceforge.net )?



I don't really care how I get email notifications - I just want them and I can't use TravisCI.










share|improve this question


























    up vote
    -1
    down vote

    favorite












    I started writing a little tool that basically can do something (ex. compile or test code) and then send an email if it fails.



    https://github.com/JohnReedLOL/EmailTestingBot



    I want to add a feature where this tool can programmatically look at the last commit in the working directory, look at the author of the commit, extract their email, and then email that person whether their commit resulted in a pass or a failure.



    For example, I want it to do something like: Git: See my last commit



    Where the email basically says:



    Subject: Test Results



    Message: All your tests passed in dev for commit 0e39756383662573.



    Does Jenkins provide this functionality already? I want to make my setup email the person who put in the most recent commit.



    Also, is there a way I can obtain the email of the author of the most recent commit programmatically (ex. perhaps with http://www.eclipse.org/jgit/ or http://javagit.sourceforge.net )?



    I don't really care how I get email notifications - I just want them and I can't use TravisCI.










    share|improve this question
























      up vote
      -1
      down vote

      favorite









      up vote
      -1
      down vote

      favorite











      I started writing a little tool that basically can do something (ex. compile or test code) and then send an email if it fails.



      https://github.com/JohnReedLOL/EmailTestingBot



      I want to add a feature where this tool can programmatically look at the last commit in the working directory, look at the author of the commit, extract their email, and then email that person whether their commit resulted in a pass or a failure.



      For example, I want it to do something like: Git: See my last commit



      Where the email basically says:



      Subject: Test Results



      Message: All your tests passed in dev for commit 0e39756383662573.



      Does Jenkins provide this functionality already? I want to make my setup email the person who put in the most recent commit.



      Also, is there a way I can obtain the email of the author of the most recent commit programmatically (ex. perhaps with http://www.eclipse.org/jgit/ or http://javagit.sourceforge.net )?



      I don't really care how I get email notifications - I just want them and I can't use TravisCI.










      share|improve this question













      I started writing a little tool that basically can do something (ex. compile or test code) and then send an email if it fails.



      https://github.com/JohnReedLOL/EmailTestingBot



      I want to add a feature where this tool can programmatically look at the last commit in the working directory, look at the author of the commit, extract their email, and then email that person whether their commit resulted in a pass or a failure.



      For example, I want it to do something like: Git: See my last commit



      Where the email basically says:



      Subject: Test Results



      Message: All your tests passed in dev for commit 0e39756383662573.



      Does Jenkins provide this functionality already? I want to make my setup email the person who put in the most recent commit.



      Also, is there a way I can obtain the email of the author of the most recent commit programmatically (ex. perhaps with http://www.eclipse.org/jgit/ or http://javagit.sourceforge.net )?



      I don't really care how I get email notifications - I just want them and I can't use TravisCI.







      scala jenkins sbt devops sbt-0.13






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 8 at 4:50









      Michael Lafayette

      1,233831




      1,233831
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote













          I will try to give solutions part by part.



          Part 1 :
          Yes, you can run ShellScript(Shell Commands) from Jenkins Link.



          Part 2
          How to get the Email Id and other Stuff from GitCommit.
          For that Jenkins sever should have git command installed in build server.
          Create one conf file ex. /conf/reference which have



          app {
          git {
          commit = "CURRENT_COMMIT"
          repo = "CURRENT_REPO"
          timestamp = "CURRENT_TIMESTAMP"
          emailId = "EMAIL_ID"
          }
          }


          When making your build run the command



          sed -i'' "s/CURRENT_COMMIT/$(git rev-parse HEAD)/g" conf/reference.conf
          sed -i'' "s^CURRENT_REPO^$(git config --get remote.origin.url)^g" conf/reference.conf
          sed -i'' "s/CURRENT_TIMESTAMP/$(git show -s --format=%ci HEAD)/g" conf/reference.conf
          sed -i'' "s/EMAIL_ID/git --no-pager show -s --format='%an <%ae>' CURRENT_COMMIT/g" conf/reference.conf


          above code will put the values in reference.conf.
          Now you can use to get the info and send the mail. As far as I know, Jenkins gives the capability to send the Email. Jenkins work on the environment variables rather than putting this into reference.conf you can put this in Environment variable and use the environment variables to send the mail.



          FYI: I haven't tested this code but as far as I remember working in Jenkins, we used to send email through this way.



          #HappyCoding






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            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: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            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
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53201719%2fhow-do-i-get-the-last-commit-programmatically-in-java-code-jenkins-sbt%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








            up vote
            1
            down vote













            I will try to give solutions part by part.



            Part 1 :
            Yes, you can run ShellScript(Shell Commands) from Jenkins Link.



            Part 2
            How to get the Email Id and other Stuff from GitCommit.
            For that Jenkins sever should have git command installed in build server.
            Create one conf file ex. /conf/reference which have



            app {
            git {
            commit = "CURRENT_COMMIT"
            repo = "CURRENT_REPO"
            timestamp = "CURRENT_TIMESTAMP"
            emailId = "EMAIL_ID"
            }
            }


            When making your build run the command



            sed -i'' "s/CURRENT_COMMIT/$(git rev-parse HEAD)/g" conf/reference.conf
            sed -i'' "s^CURRENT_REPO^$(git config --get remote.origin.url)^g" conf/reference.conf
            sed -i'' "s/CURRENT_TIMESTAMP/$(git show -s --format=%ci HEAD)/g" conf/reference.conf
            sed -i'' "s/EMAIL_ID/git --no-pager show -s --format='%an <%ae>' CURRENT_COMMIT/g" conf/reference.conf


            above code will put the values in reference.conf.
            Now you can use to get the info and send the mail. As far as I know, Jenkins gives the capability to send the Email. Jenkins work on the environment variables rather than putting this into reference.conf you can put this in Environment variable and use the environment variables to send the mail.



            FYI: I haven't tested this code but as far as I remember working in Jenkins, we used to send email through this way.



            #HappyCoding






            share|improve this answer

























              up vote
              1
              down vote













              I will try to give solutions part by part.



              Part 1 :
              Yes, you can run ShellScript(Shell Commands) from Jenkins Link.



              Part 2
              How to get the Email Id and other Stuff from GitCommit.
              For that Jenkins sever should have git command installed in build server.
              Create one conf file ex. /conf/reference which have



              app {
              git {
              commit = "CURRENT_COMMIT"
              repo = "CURRENT_REPO"
              timestamp = "CURRENT_TIMESTAMP"
              emailId = "EMAIL_ID"
              }
              }


              When making your build run the command



              sed -i'' "s/CURRENT_COMMIT/$(git rev-parse HEAD)/g" conf/reference.conf
              sed -i'' "s^CURRENT_REPO^$(git config --get remote.origin.url)^g" conf/reference.conf
              sed -i'' "s/CURRENT_TIMESTAMP/$(git show -s --format=%ci HEAD)/g" conf/reference.conf
              sed -i'' "s/EMAIL_ID/git --no-pager show -s --format='%an <%ae>' CURRENT_COMMIT/g" conf/reference.conf


              above code will put the values in reference.conf.
              Now you can use to get the info and send the mail. As far as I know, Jenkins gives the capability to send the Email. Jenkins work on the environment variables rather than putting this into reference.conf you can put this in Environment variable and use the environment variables to send the mail.



              FYI: I haven't tested this code but as far as I remember working in Jenkins, we used to send email through this way.



              #HappyCoding






              share|improve this answer























                up vote
                1
                down vote










                up vote
                1
                down vote









                I will try to give solutions part by part.



                Part 1 :
                Yes, you can run ShellScript(Shell Commands) from Jenkins Link.



                Part 2
                How to get the Email Id and other Stuff from GitCommit.
                For that Jenkins sever should have git command installed in build server.
                Create one conf file ex. /conf/reference which have



                app {
                git {
                commit = "CURRENT_COMMIT"
                repo = "CURRENT_REPO"
                timestamp = "CURRENT_TIMESTAMP"
                emailId = "EMAIL_ID"
                }
                }


                When making your build run the command



                sed -i'' "s/CURRENT_COMMIT/$(git rev-parse HEAD)/g" conf/reference.conf
                sed -i'' "s^CURRENT_REPO^$(git config --get remote.origin.url)^g" conf/reference.conf
                sed -i'' "s/CURRENT_TIMESTAMP/$(git show -s --format=%ci HEAD)/g" conf/reference.conf
                sed -i'' "s/EMAIL_ID/git --no-pager show -s --format='%an <%ae>' CURRENT_COMMIT/g" conf/reference.conf


                above code will put the values in reference.conf.
                Now you can use to get the info and send the mail. As far as I know, Jenkins gives the capability to send the Email. Jenkins work on the environment variables rather than putting this into reference.conf you can put this in Environment variable and use the environment variables to send the mail.



                FYI: I haven't tested this code but as far as I remember working in Jenkins, we used to send email through this way.



                #HappyCoding






                share|improve this answer












                I will try to give solutions part by part.



                Part 1 :
                Yes, you can run ShellScript(Shell Commands) from Jenkins Link.



                Part 2
                How to get the Email Id and other Stuff from GitCommit.
                For that Jenkins sever should have git command installed in build server.
                Create one conf file ex. /conf/reference which have



                app {
                git {
                commit = "CURRENT_COMMIT"
                repo = "CURRENT_REPO"
                timestamp = "CURRENT_TIMESTAMP"
                emailId = "EMAIL_ID"
                }
                }


                When making your build run the command



                sed -i'' "s/CURRENT_COMMIT/$(git rev-parse HEAD)/g" conf/reference.conf
                sed -i'' "s^CURRENT_REPO^$(git config --get remote.origin.url)^g" conf/reference.conf
                sed -i'' "s/CURRENT_TIMESTAMP/$(git show -s --format=%ci HEAD)/g" conf/reference.conf
                sed -i'' "s/EMAIL_ID/git --no-pager show -s --format='%an <%ae>' CURRENT_COMMIT/g" conf/reference.conf


                above code will put the values in reference.conf.
                Now you can use to get the info and send the mail. As far as I know, Jenkins gives the capability to send the Email. Jenkins work on the environment variables rather than putting this into reference.conf you can put this in Environment variable and use the environment variables to send the mail.



                FYI: I haven't tested this code but as far as I remember working in Jenkins, we used to send email through this way.



                #HappyCoding







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 8 at 6:37









                Merom

                4751621




                4751621






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • 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%2fstackoverflow.com%2fquestions%2f53201719%2fhow-do-i-get-the-last-commit-programmatically-in-java-code-jenkins-sbt%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







                    這個網誌中的熱門文章

                    Xamarin.form Move up view when keyboard appear

                    Post-Redirect-Get with Spring WebFlux and Thymeleaf

                    Anylogic : not able to use stopDelay()