7

I'm working on a multibranch (A) job that is being triggered from another one (B). I want to do the deploy of my project only if there are changes in this project (A). By changes I mean from the last build of this job (I've seen the jenkins pannel gives you this info when you build, so I thought it would be possible to read it somewhere).

enter image description here)

So, is there any way of checking it in a pipeline?

Jaime Alcántara Arnela
  • 2,062
  • 5
  • 25
  • 56
  • Possible duplicate of [How to get the changes since the last successful build in jenkins pipeline?](https://stackoverflow.com/questions/38084806/how-to-get-the-changes-since-the-last-successful-build-in-jenkins-pipeline) – StephenKing Jun 28 '18 at 10:58
  • @StephenKing not exactly what I'm asking. He ask for the changes, I just want to know if there are any changes. The code should be easier in my case, if you read the answer given to that question you will see that they center on extracting the different changes to the console (something I don't need). – Jaime Alcántara Arnela Jul 11 '18 at 11:02

1 Answers1

13

Finally I found the answer. If you just want to know if there are changes in that build you can do:

if(currentBuild.changeSets.size() > 0) {
    //There are changes
}
else {
    //No changes
}
Jaime Alcántara Arnela
  • 2,062
  • 5
  • 25
  • 56
  • currentBuild.changeSets.size() fails, is there a package that I am missing? – Fred Jun 29 '22 at 21:02
  • 1
    Found my mistake, I forgot to put `currentBuild.changeSets.size()` in a `script{}` bracket. – Fred Jun 30 '22 at 14:11