Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement setters instead of constructor for optional parameters #246

Merged
merged 6 commits into from
Jan 22, 2022
Merged

Implement setters instead of constructor for optional parameters #246

merged 6 commits into from
Jan 22, 2022

Conversation

westarne
Copy link
Contributor

@westarne westarne commented Oct 2, 2019

Concerning #245

I was not able to reproduce the original issue, but comparing with other plugins this might do the trick. For now this was not tested by me on an actual Jenkins and I could only test if it works for me as it did before. It would be great if someone, for whom the v1.20 is failing, could test this build. (@adrian-at-dmi, @tschlue, @r4d1um)

If you are not able to build this plugin (and you trust me), here is a locally built .hpi:
stashNotifier.zip

@westarne
Copy link
Contributor Author

westarne commented Oct 4, 2019

I have now tested this build on my Jenkins and it still works for me. So it does not seem to break anything at least. But I cannot verify whether this actually makes the parameters optional as intended, but it should...

@scaytrase
Copy link
Member

@westarne it does not break already configured instances? I'll try to test it on my jenkins instance on weekend

@westarne
Copy link
Contributor Author

westarne commented Oct 4, 2019

I've tested this via manually replacing the old *.jpi in the plugins folder, so that worked without changing anything configured. I'm not sure if this would work via the usual install process as well, but I think it should.

@scaytrase
Copy link
Member

sounds good

@proski
Copy link
Contributor

proski commented Dec 3, 2019

I believe this change will make it possible to use notifyBitbucket without arguments in declarative pipelines. That would be very good! I can do it by surrounding that command with script { ... }, but it shouldn't be necessary. There are no required arguments if the URL and credentials are set up in the global settings.

However, I'm concerned that this PR appears to be changing more code than necessary. In particular, it should not be adding extra settings. It's better to keep the configuration to the minimum. Even some of the existing overrides don't make sense to me. For instance, "Override project key". Why would anyone do it? And this PR is adding "Build Status". Why would anyone use anything but the actual build result?

In any case, adding new user interface should be a separate PR, with a separate justification.

@westarne
Copy link
Contributor Author

westarne commented Dec 3, 2019

Both project key and build status are useful and already implemented and merged from different previous issues.
They are not added in this PR.

Override the project key is useful to push separate statuses for different build steps in the pipeline as well as the build status. (this is actually the buildName not projectKey i meant)

You can this way use the custom buildStatus for example to say that the build step was successful and the test step is in progress. By setting the buildStatus to succesful once you could otherwise never push a "in progress" anymore after that. But as i said, both were implemented before and not in this PR.

@scaytrase
Copy link
Member

Yes, that's true, override project key and build status were implemented before

@darxriggs
Copy link
Collaborator

I just saw that there is a merge conflict to be resolved.

So let me ask what is the current state of this pull request and the next steps?

@scaytrase
Copy link
Member

So let me ask what is the current state of this pull request and the next steps?

On #245 people report problem is gone when they use script wrapper, so I'm not sure we are fixing a problem here. But as an improvement this might be good

@westarne
Copy link
Contributor Author

westarne commented Jan 6, 2020

I've resolved the conflicts.

In my opinion this change could fix the issue #245. But I was not able to really test this because I could not reproduce the initial issue. It'd great if someone could test this manually (e.g. with the provided .hpi) who is able to reproduce the initial issue.

In general this should not create additional issues either way even if it does not fix #245 but testing it in integration first is still important I think.

@darxriggs
Copy link
Collaborator

@westarne Do you know mvn hpi:run? It is very handy to interactively try out the latest changes during development.

I suggest to run it, install the "Pipeline: Declarative" plugin and try a Jenkinsfile like this:

pipeline {
   agent any

   stages {
      stage('Testing') {
         steps {
            echo 'Some Message'
            notifyBitbucket(
                stashServerBaseUrl: 'https://localhost',
                projectKey: 'KEE',
                commitSha1: 'shaaaaaaaa',
                credentialsId: 'example-id',
                considerUnstableAsSuccess: false,
                disableInprogressNotification: false,
                ignoreUnverifiedSSLPeer: false,
                includeBuildNumberInKey: false,
                prependParentProjectKey: false,
            )
         }
      }
   }
}

You should be able to reproduce the issue with this pipeline on the current master or latest tag 1.20 state and also be able to verify in your branch that it is fixed.

@westarne
Copy link
Contributor Author

westarne commented Jan 6, 2020

Do you know mvn hpi:run? It is very handy to interactively try out the latest changes during development.

Thank you for this advice, I was able to reproduce the original issue with this. And it seems to be resolved with this pull request.
Because the bitbucket server I usually use is behind a corporate firewall I was not able to actually push a status yet, because some other configurations need to be done. But using the release/1.x state with buildName: '', buildStatus: '' I get the exact same output I get with this PR branch without these parameters specified (and I get the initial missing parameters problem of course when I do not set the params on the release/1.x branch).

return considerUnstableAsSuccess;
@DataBoundSetter
public void setStashServerBaseUrl(String stashServerBaseUrl) {
this.stashServerBaseUrl = stashServerBaseUrl != null && stashServerBaseUrl.endsWith("/")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StringUtils#stripEnd could be used.

@westarne
Copy link
Contributor Author

Implemented the proposed optimizations

this.prependParentProjectKey = prependParentProjectKey;
this.disableInprogressNotification = disableInprogressNotification;
this.considerUnstableAsSuccess = considerUnstableAsSuccess;
StashNotifier(
Copy link
Collaborator

@darxriggs darxriggs Feb 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am thinking if the number of constructors can be reduced even more? Is this one really required?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about that, and neither am I that the test cases existing as well as the ones I can do locally cover all potential use cases. So I've kept it to be on the safe side.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this is a new one and another one has been removed.

In other plugins it's often handled the way to keep all old constructors for backward compatibility and annotate them with @Deprecated. That's something the maintainers should decide.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh you're right. Then I'm not totally sure, what the constructor was meant for. I think it's just the old DataBoundConstructor without all of the optional parameters. So I could just move the logic in the no-argument constructor.

Copy link
Contributor Author

@westarne westarne Apr 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was some time out of the country and noticed that I did not push the change before. Done that now.

@coxalass
Copy link

coxalass commented Jun 9, 2021

Hello,

I guess this might also fix the following issue : #266

Is there anything preventing this PR from being merged ?

Kind regard,

Copy link
Member

@jetersen jetersen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is usually best practice for Jenkins plugins and follows JCasC recommendations as well.

@scaytrase
Copy link
Member

At the moment I think I can accept this PR, but this should be updated

@scaytrase
Copy link
Member

@westarne a lot of compilation errors

@westarne
Copy link
Contributor Author

@westarne a lot of compilation errors

never merge on the git website, noted. Was just missing a } as far as I can tell. Added that

Copy link
Member

@scaytrase scaytrase left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@scaytrase scaytrase merged commit 5d1ba63 into jenkinsci:release/1.x Jan 22, 2022
@scaytrase
Copy link
Member

Thanks @westarne . I'll try try to release this as soon as I can

@westarne westarne deleted the feature/optional-parameters branch January 22, 2022 15:41
@scaytrase
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants