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

Build a PR with multiple jobs? #560

Closed
maxime-michel opened this issue Feb 16, 2022 · 6 comments
Closed

Build a PR with multiple jobs? #560

maxime-michel opened this issue Feb 16, 2022 · 6 comments
Labels

Comments

@maxime-michel
Copy link

maxime-michel commented Feb 16, 2022

What feature do you want to see added?

When a pull request is opened/updated, Jenkins automatically builds it and reports its status in the Builds tab of the PR. This is great but we would like to start breaking up this job into multiple ones, as we have seen is possible on GitHub:

Screenshot 2022-02-16 at 15 17 06

I was able to replicate this behaviour by running a second job and updating the build status endpoint myself. But that's extremely brittle as I can't hook into the job lifecycle as well as this plugin is doing. Is there a way this could somehow be supported out of the box?

I've seen it is possible to achieve this by having multiple Jenkinsfile inside the same monorepo. But what I would want instead is to manage those 'actions' outside the repository, so I can use them across multiple projects. The plugin would therefore need to support the use case.

Upstream changes

-

@KalleOlaviNiemitalo
Copy link
Contributor

KalleOlaviNiemitalo commented Feb 16, 2022

AFAIK that feature does not exist yet, but here's a draft of how it could work. Define a bitbucketBuildStatus option and a bitbucketBuildStatus step, that could then be used in pipelines as follows:

pipeline {
    options {
        // Stop Jenkins from reporting the build status of the pipeline as a whole,
        // like it does by default.  But if there is a syntax error in the pipeline,
        // then the option won't take effect.
        bitbucketBuildStatus skip: true
    }
    stages {
        stage('Parallel') {
            parallel {
                stage('Java 8') {
                    options {
                        // Jenkins would report an INPROGRESS status when this stage
                        // starts, and SUCCESSFUL or FAILED when the stage finishes.
                        bitbucketBuildStatus key: 'Java 8'
                    }
                    steps {
                        //
                    }
                }
                stage('Java 11') {
                    steps {
                        // Jenkins would report an INPROGRESS status when this step
                        // starts, and SUCCESSFUL or FAILED when the step finishes.
                        bitbucketBuildStatus(key: 'Java 11') {
                            //
                        }
                    }
                }
            }
        }
    }
}

Would this kind of feature work for your purposes, or did you mean something different?

One problem with this draft is that Jenkins has a mutable Result for the build as a whole and also a Result for each stage. If something sets an error result for the build only, then it might be impossible to associate that with just one build status sent to Bitbucket.

Are you using Bitbucket Cloud or Bitbucket Server?

@KalleOlaviNiemitalo
Copy link
Contributor

Other plugins provide steps:

Each of those plugins has documentation that shows a try-catch statement for reporting successful or failed builds.

@maxime-michel
Copy link
Author

maxime-michel commented Feb 17, 2022

Thanks a lot, I had no idea these steps existed! I need to experiment with them ASAP, they're certainly much easier to work with than observing the job to then POST to the endpoint myself.

We're using Bitbucket Server, by the way.

@mdealer
Copy link

mdealer commented Mar 1, 2022

Other plugins provide steps:

* [`bitbucketStatusNotify`](https://www.jenkins.io/doc/pipeline/steps/bitbucket-build-status-notifier/#bitbucketstatusnotify-notify-a-build-status-to-bitbucket)

* [`notifyBitbucket`](https://www.jenkins.io/doc/pipeline/steps/stashNotifier/#notifybitbucket-notify-bitbucket-instance)

Each of those plugins has documentation that shows a try-catch statement for reporting successful or failed builds.

bitbucketStatusNotify: does not work for my scripted pipeline. It expects 'scm' to be the actual repo that I'm trying to post status to, but it's only the case for the simplest of my pipelines.

notifyBitbucket: seems like it's for server only but I use cloud. Has anyone tried it with cloud?

It might be simpler to call Bitbucket API directly in my case. If Bitbucket Branch Source provided a step for this, it would have been helpful.

@KalleOlaviNiemitalo
Copy link
Contributor

KalleOlaviNiemitalo commented Mar 1, 2022

bitbucketStatusNotify: does not work for my scripted pipeline. It expects 'scm' to be the actual repo that I'm trying to post status to, but it's only the case for the simplest of my pipelines.

README shows repoSlug and commitId parameters. Can you use those to post to a different repository?

notifyBitbucket: seems like it's for server only but I use cloud. Has anyone tried it with cloud?

jenkinsci/stashnotifier-plugin#85 says it doesn't work with Bitbucket Cloud.

@mdealer
Copy link

mdealer commented Mar 1, 2022

bitbucketStatusNotify: does not work for my scripted pipeline. It expects 'scm' to be the actual repo that I'm trying to post status to, but it's only the case for the simplest of my pipelines.

README shows repoSlug and commitId parameters. Can you use those to post to a different repository?

I tried, but got a seemingly unrelated error. Apparently, my 'scm' is not a 'GitSCM', but I know for sure that it is the case, so it must be some general assumption related to scripted pipelines not working here:

java.lang.Exception: Bitbucket build notifier requires a git repo or a mercurial repo as SCM at org.jenkinsci.plugins.bitbucket.BitbucketBuildStatusHelper.createBuildStatusResources(BitbucketBuildStatusHelper.java:85) at org.jenkinsci.plugins.bitbucket.BitbucketBuildStatusHelper.createBuildStatusResources(BitbucketBuildStatusHelper.java:145) at org.jenkinsci.plugins.bitbucket.BitbucketBuildStatusHelper.notifyBuildStatus(BitbucketBuildStatusHelper.java:235) at org.jenkinsci.plugins.bitbucket.BitbucketBuildStatusNotifierStep$Execution.run(BitbucketBuildStatusNotifierStep.java:202) at org.jenkinsci.plugins.bitbucket.BitbucketBuildStatusNotifierStep$Execution.run(BitbucketBuildStatusNotifierStep.java:148)

notifyBitbucket: seems like it's for server only but I use cloud. Has anyone tried it with cloud?

jenkinsci/stashnotifier-plugin#85 says it doesn't work with Bitbucket Cloud.

Thanks for the info.

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

No branches or pull requests

4 participants