简体   繁体   中英

source code changes either through Git or Jenkins

Our requirement is as follows - We are using Git and Jenkins We would like to find out the source code changes from last successful build and current changes which are there on github. ( Branch is same ) This change list we want to send in email ( not as attachment )

We have tried using git diff, email-ext plugin of jenkins. What could be the different ways to achieve this.

I would recommend a combination of git hooks and the Jenkins Remote JSON API .

You can get information using the JSON API for the last successful build with a URL like this:

http://<hostname>:<port>/job/<test_name>/lastSuccessfulBuild/api/json

JSON will get returned as a result of GET 'ing that URL. Inside of that JSON will be a hash entitled buildsByBranchName . Inside of that will be at least one, possibly more branches listed. You may want origin/master , although it will depend the branch you're merging into. Inside of that is an attribute named revision and inside that, SHA1 . This can then be used in a git diff .

With the git hooks , I'd recommend using the post-receive hook. This is essentially a bash script, but it can wrap a more complex script, such as Python . One thing to keep in mind here is that if the current commit is a merge, what you want to check out may actually be one or two commits above the current one.

In any case, say you wrap a Python script inside the post-receive hook. Inside that Python script, you can add code that calls the JSON URL I mentioned above to determine the commit hash for the last successful build.

Then you can use that in conjunction with the latest commit hash (which you can get from within the git hook using the standard git command line tools, of which there are a variety of methods to accomplish this) and then do a git diff using the commit hash you got the for last successful build and the most recent build to get the changes between them.

You can then email these changes to the list of people you would like from within the script.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM