jenkinsci / last-changes-plugin

https://plugins.jenkins.io/last-changes
https://plugins.jenkins.io/last-changes/
31 stars 31 forks source link

Compare current workspace diff with remote #10

Open ltozi opened 6 years ago

ltozi commented 6 years ago

I'm in a particular case where I have to deploy sources from one repository (our deploy repo) to customer repository (release source to customer).

I saw that scm is caluclated where the scm is the one where files were committed and for which a build trigger occurred:

https://github.com/jenkinsci/last-changes-plugin/blob/master/src/main/java/com/github/jenkins/lastchanges/LastChangesPublisher.java#L155

In my pipeline I do a second scm checkout and I would like to diff in a way like this:

svn diff -r PREV:BASE | diff2html -i stdin -s side -F report.html

Where BASE is workspace with incoming new changes for the customer repo.

Is it possible to point to a different repo to show diff?

Thanks, Luigi

rmpestano commented 6 years ago

Hi @ltozi,

I think it is possible but it needs to be implemented, the svn diff is done here, it gets source and target revisions from the same repository:

diff.setSources(SvnTarget.fromURL(repository.getLocation(), SVNRevision.create(previousRevision)),
                    SvnTarget.fromURL(repository.getLocation(), SVNRevision.create(currentRevision)));

in above example both source and target are from the same repo but it could be different ones.

Now the question is, how can we pass the second repository information to the plugin? besides the url you'll also need to pass the credentials.

Currently we don't need to worry about that because we get from build trigger.

Having said that if you provide a PR with this implemented in both SVN and GIT I can review and accept the pull request.

ltozi commented 6 years ago

Hi @rmpestano,

I'm not a "Jenkins pipeline guru", but what do you think if lastChanges plugin could take scm reference directly from the directory where the command is run?

Example: ` //1 checkout scm lastChanges() //How actually works

//2 dir("customs/svn/dir") { checkout scm //with jenkins provided credential etc... lastChanges() }

//3 dir("customs/svn/dir") { def scmObj = checkout scm //with jenkins provided credential etc... //use scmObj in lastChanges? } `

rmpestano commented 6 years ago

Hi, I'm really out of time to try and implement that but if you will here are the things that must be changed in order to make //3 work:

You need to add another parameter (of type scm) here and if it is not null then call last change here passing the additional repository and later create another method here which receives two repositories as parameters and finnaly call the diff using the additional repository as I commend here.

Also to accept the PR there must be a test here.

Thank you for the feedback.