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

Different multibranch pipelines use the same key #175

Open
Wilfred opened this issue Oct 17, 2017 · 6 comments
Open

Different multibranch pipelines use the same key #175

Wilfred opened this issue Oct 17, 2017 · 6 comments

Comments

@Wilfred
Copy link
Contributor

Wilfred commented Oct 17, 2017

Suppose I have two separate multibranch pipeline jobs, foo-unit and foo-integration. When I push a branch to master, the following notifications are sent to Stash:

{
    "state": "SUCCESSFUL",
    "key": "master-http:\\/\\/ci.dev.example\\/",
    "name": "foo-unit / master #11",
    "description": "built by Jenkins @ http://ci.dev.example/",
    "url": "http://ci.dev.example/job/foo-unit/job/master/11/"
}
{
    "state": "SUCCESSFUL",
    "key": "master-http:\\/\\/ci.dev.example\\/",
    "name": "foo-integration / master #11",
    "description": "built by Jenkins @ http://ci.dev.example/",
    "url": "http://ci.dev.example/job/foo-integration/job/master/11/"
}

These both have the same key. As a result, Stash uses the last build and ignores the first.

I can't use includeBuildNumberInKey because if build 1 of foo-integration is red, but build 2 of foo-integration is green, Stash thinks they are distinct jobs. This gives a key of the form "master-2-http:\\/\\/ci.dev.example\\/".

If I use step([$class: 'StashNotifier', prependParentProjectKey: true]) I get a key that's unique to the current build:

{
    "state": "SUCCESSFUL",
    "key": "foo-integration-master-http:\\/\\/ci.dev.example\\/",
    "name": "foo-integration / master #11",
    "description": "built by Jenkins @ http://ci.dev.example/",
    "url": "http://ci.dev.example/job/foo-integration/job/master/11/"
}

However, this is subtle gotcha. It would be nice if this plugin used the build name, not the branch name, for multibranch pipelines.

I think the correct solution would be to change StashNotifier#getDefaultBuildKey to use something like if build instanceOf MultiBranchProject, but this would introduce a dependency on that plugin.

What do you think is a good solution here?

@scaytrase
Copy link
Member

Hi, @Wilfred

Can you try override projectKey value for the notifier manually for your needs for both jobs?

this one https://github.com/jenkinsci/stashnotifier-plugin/blob/release/1.x/src/main/java/org/jenkinsci/plugins/stashNotifier/StashNotifier.java#L151

@Wilfred
Copy link
Contributor Author

Wilfred commented Oct 17, 2017

Yep, setting the projectKey for just one job of my two jobs works as a solution.

However, this requires every user with multiple jobs that are multibranch pipelines to do the same thing. Ideally stashnotifier-plugin wouldn't require every user to set projectKey or prependParentProjectKey.

@scaytrase
Copy link
Member

Initially, prepend parent job key option was introduced in #60 by me for solving your initial problem - create unique keys for multibranch projects operating the same repo. I'm not sure that configuring single option is a really big problem to make this plugin hardly tied to multibranch plugin. If you have a decision without declaring a dependency - PR is always welcome

@Wilfred
Copy link
Contributor Author

Wilfred commented Oct 18, 2017

@scaytrase OK, how about this?

If env.BRANCH_NAME is the same as the project name, then we automatically prepend the parent job key?

@scaytrase
Copy link
Member

How do you resolve false positives, i.e classic non-multibranch job, named master building only master branch?

I think it's ok to introduce some optional global-configured project key guesser, but it should be off by default anyway for BC reasons to not get any key renamed unintentionally

@Wilfred
Copy link
Contributor Author

Wilfred commented Oct 30, 2017

If there's a classic non-multibranch job named master, prepending the parent job key is harmless because StashNotifier handles the parent being null.

If the classic non-multibranch job is in a folder, then the the parent job key will be non-null, but that seems harmless to me.

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

No branches or pull requests

2 participants