How get latest commit from gocd and detect did it change some specific folder?

1.8k views Asked by At

I'm using gocd continious delivery tool + git. My project consists of many subprojects. I don't want to rebuild all subprojects on each commit and thus created one pipeline for each subproject. I know, that for each pipeline, say for project1, I have to choose appropriate working dir and run smth like that:

  1. get git commit which triggered gocd build.
  2. detect whether changes in that commit contain project1 folder
  3. if changes in whole project also affected project1 folder run custom build command for project1.

How may I get commit from gocd which triggered current build? Is it simply git's latest commit or not? I thing latest commit is not safe option in case of many concurrent commits, that's why I want to get it directly from gocd - I hope it stores it for each build trigger event. How detect commit affects on folder in bash?

3

There are 3 answers

0
RaviTezu On BEST ANSWER

As you said, you are using a different pipeline for each sub project.

For a quick hack, you can use the "Blacklist" field when adding a material. It basically says the pipeline, not to trigger(start building) when these files(entered in the Blacklist field) are changed in the commit.

I know, it is a bit tricky, but if you don't change your sub-poject folders more often, this can solve your problem.

Hope this helps :)

0
LeGEC On

How detect commit affects on folder in bash?

You can use git diff --name-only.

git diff --name-only <commit1> <commit2>

will list the files which have been created / modified / deleted between the two commits.

git diff --name-only <commit1> <commit2> -- directory/path/

will list the modifications inside directory/path/

0
AudioBubble On

Partial answer given here (each commit writed to some environment variable) https://github.com/gocd/gocd/issues/2001