3

I have a git repo. I need to get the changed files in json format or any file format, when the Jenkins build is done

RAm Prasad
  • 81
  • 1
  • 5
  • While these do not provide a concrete answer to your question, you can have a look to [this](https://stackoverflow.com/questions/17979573/how-to-find-out-list-of-all-changed-files-in-git-for-full-jenkins-build-and-not) and [this](https://stackoverflow.com/questions/6260383/how-to-get-list-of-changed-files-since-last-build-in-jenkins-hudson/39862273). – dstrants Dec 06 '18 at 12:05

2 Answers2

4

You can also do this: git diff --name-only $GIT_PREVIOUS_COMMIT $GIT_COMMIT in your build script, pipe it to a file and you should have the list of all the files that have changed in that particular build. This is assuming you are using the Git Plugin for Jenkins.

The git plugin sets several environment variables you can use in your scripts:

GIT_COMMIT - SHA of the current GIT_BRANCH - Name of the remote repository (defaults to origin), followed by name of the branch currently being used, e.g. "origin/master" or "origin/foo"

GIT_LOCAL_BRANCH - Name of the branch on Jenkins. When the "checkout to specific local branch" behavior is configured, the variable is published. If the behavior is configured as null or **, the property will contain the resulting local branch name sans the remote name.

GIT_PREVIOUS_COMMIT - SHA of the previous built commit from the same branch (not set on first build on a branch)

If you want this file to be a build artifact, you can use the Archive Artifacts post build step.

Yogesh_D
  • 17,656
  • 10
  • 41
  • 55
0

You can use inbuilt email template which will send you the list for file changes in the current build.

post {
  always {
    emailext body: ''
    '${SCRIPT, template="groovy-html.template"}'
    '',
    subject: "${env.JOB_NAME} - Build # ${env.BUILD_NUMBER} - Successful",
      mimeType: 'text/html', to: "email list"
  }
}

If you want the changes in separate file you can modify the groovy-html.template as per your requirement

Pardeep Dhingra
  • 3,916
  • 7
  • 30
  • 56
Amit Nanaware
  • 3,203
  • 1
  • 6
  • 19