jenkinsci / jenkinsci/stashnotifier-plugin

Different multibranch pipelines use the same key

Open
#175 6 comments 1 reaction 0 assignees View on GitHub
Dominant language
Java
Stars
167
Forks
139
PR merge metrics
No merged PRs in 30d

Description

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:

```json
{
"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/"
}
```

```json
{
"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:

```json
{
"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?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.