0

I've inherited a truly ancient Jenkins server that needed a rebuild from the OS up, and I'm at the point of migrating our builds over. However there's one multibranch pipeline in particular with dozens of feature/bugfix/etc branches and builds that take significant amounts of time and resources. When I initially set up its multibranch pipeline on the test cluster the initial builds of all the branches monopolized all the resources for hours until I killed them.

What I would like to happen is have all the branches initially imported but not built until there's another push or PR for the branch. Currently I've applied the "Suppress automatic SCM triggering" strategy defined, but as soon as I remove it Jenkins attempts to build all branches.

What I think may be a viable solution would be to set the status on each branch to something other than 'Not Built', and then remove the suppression strategy.

I've run across the below Groovy script that will change the result of a particular build, but it seems to require that there actually be a previous build to change the status of.

import com.cloudbees.groovy.cps.NonCPS
import jenkins.model.*
import hudson.model.Result

@NonCPS
def getProject(projectName) {
    // CloudBees folder plugin is supported, you can use natural paths:
    // in a postbuild action use `manager.hudson`
    // in the script web console use `Jenkins.instance`
    def project = jenkins.model.Jenkins.instance.getItemByFullName(projectName)
    if (!project) {error("Project not found: $projectName")}
    return project
}

project = getProject('foo/bar')
build = project.getBuildByNumber(2443)
// build = project.getBuild(project, '2443')

build.@result = hudson.model.Result.SUCCESS
// build.@result = hudson.model.Result.NOT_BUILT
// build.@result = hudson.model.Result.UNSTABLE
// build.@result = hudson.model.Result.FAILURE
// build.@result = hudson.model.Result.ABORTED

Source: https://stackoverflow.com/a/45708131/1064767

Is there a way to change the status of the project itself, or a way to create a "dummy" build with a particular status?

Sammitch
  • 30,782
  • 7
  • 50
  • 77

1 Answers1

1

Note: If you just want the jobs and don't care about build history the Job Import plugin will likely fit your use case much more neatly.

I've spent the better part of the last day digging through Jenkins source and bothering the community, but there doesn't seem to be a good way to dummy up build results like this. However, it is technically possible to simply clone over all or parts of /var/jenkins_home/jobs which will pull over the job config and history in their entirety. After that you just need to restart Jenkins so it will recognize the new config.

While some in the Jenkins community will rightly try to warn you off of cloning data like this, if you're stuck without other options it can work after a fashion with the following caveats:

  1. Do this on a test server first. I cannot guarantee that my experience is universal, and results may vary wildly depending on your particular builds and plugins.
  2. Your old builds will likely reference plugins that you may not have installed on the new server, or plugins of different versions. In my experience Jenkins raised "Old Data" notices about these, and installing the missing plugins and restarting fixed those. There's also the option of simply discarding the data as well.
Sammitch
  • 30,782
  • 7
  • 50
  • 77