Home > Enterprise >  git pull origin master, check if any conflicts without pull
git pull origin master, check if any conflicts without pull

Time:09-17

I want to automate a build where before creating the build i have to pull from master and then I have to build the package. But I want to have a check point to see if there is any conflict before pulling from master so that I can make the build to fail.

Can anyone please advise how to do it in gitscm for jenkins(or git also fine). I am not able to find a proper solution, maybe my understanding is not clear since i am not having development background.

Thanks in advance.

CodePudding user response:

If you're doing this work in jenkins, the build job would be working on its own sandbox, which you can destructively used since it's temporary anyway. All you need to do is check the exit status from the git pull operation, as @Romain Valeri suggests, and proceed only on success, since a git pull with a conflict exits with non-zero.

If your recipe was in bash, something like this would work:

if git pull; then
   # proceed with build
else
   # there was a conflict, abort with error
fi

or just

git pull or exit_with_error
# proceed with build

The equivalent should be simple to do in your jenkins build recipe.

CodePudding user response:

Maybe what you're looking for is the command fetch, which does almost the same thing as pull and can give you the opportunity to check the conflicts.

  • Related