How can I reconfigure a multibranch pipeline in Jenkins without changing the Jenkinsfile?
I have a shared git repository used by 12 people. I want to rebuild every branch after the branch itself gets updated or a PR gets merged into developer.
I configured a multibranch pipeline and wrote a Jenkinsfile that achieves this goal.
This Jenkinsfile is in developer, and it's now been included into more than 60 branches. This was OK at first, but now that we have so many branches, over 60 builds get queued up every time we merge a PR. It can take a very long time for all of those builds to complete. Also, the builds use up a lot of disk space, causing my disk quota on the Uni computer to be exceeded.
To solve those problems, I would like to do the following:
make Jenkins stop rebuilding the old branches. E.g. ignore branches that were last updated more than 2 weeks ago.
Make Jenkins run "deleteDir()" in the post phase of all builds.
I can easily update my Jenkinsfile to achieve these goals. But then I have to put the new Jenkinsfile into every single branch I have! So that's where I'm stuck. I really don't want to have to update every single old branch by hand.
I've had some ideas for solutions, but none of them satisfy me. I could e.g.:
Delete the old branches, but we can't do that, because this is a university module, and all branches should be kept in the repository as a kind of proof that one has been practicing writing code.
Write a script to add the new Jenkinsfile to every single branch in our repo. This would be a kind of weird look. I don't want my name to be in every single branch.
Write a script that fetches all branches from the main repo into a secondary repo, which I would then point the multibranch pipeline at. Then write another script that regularly deletes obsolete branches from this secondary repo. This sounds like so much work!! And it does not solve the issue of running deleteDir() at the end of every build.
Basically, I would like to find a way of reconfiguring my pipeline inside of Jenkins without individually updating the Jenkinsfile in every branch. Is there a way to do this?
Here is my Jenkinsfile, for reference. Could it be that I have to adapt it to be used in a "normal pipeline" rather than a "multibranch pipeline"?
def commitHash
pipeline {
agent any
triggers {
// Every branch should be rebuilt after developer is built
// This doesn't cause an infinite loop, because 'Developer builden' is a job that only specifically
// gets triggered after a commit is pushed to developer. The event will not be fired a second time
// when developer is built as a result of this upstream trigger.
upstream(upstreamProjects: 'Developer builden', threshold: hudson.model.Result.FAILURE)
}
stages {
stage('Build') {
steps {
echo 'checkout scm'
checkout scm
script {
commitHash = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%H'").trim()
}
echo 'merging into origin/developer'
sh 'git merge origin/developer'
echo 'Building..'
}
}
stage('Test') {
steps {
sh 'mvn clean package'
echo 'Testing..'
}
}
stage('Deploy') {
steps {
echo 'Deploying....'
}
}
}
post {
always {
script {
currentBuild.result = currentBuild.result ?: 'SUCCESS'
echo "build result: ${currentBuild.result}"
echo "commitSha1: ${commitHash}"
notifyBitbucket commitSha1: commitHash,
credentialsId: '<redacted>',
disableInprogressNotification: false,
considerUnstableAsSuccess: false,
ignoreUnverifiedSSLPeer: true,
includeBuildNumberInKey: false,
prependParentProjectKey: false,
projectKey: '',
stashServerBaseUrl: '<redacted>'
}
deleteDir() // This line is, unfortunately, not present in most of our older branches.
}
}
}
git version-control jenkins
add a comment |
I have a shared git repository used by 12 people. I want to rebuild every branch after the branch itself gets updated or a PR gets merged into developer.
I configured a multibranch pipeline and wrote a Jenkinsfile that achieves this goal.
This Jenkinsfile is in developer, and it's now been included into more than 60 branches. This was OK at first, but now that we have so many branches, over 60 builds get queued up every time we merge a PR. It can take a very long time for all of those builds to complete. Also, the builds use up a lot of disk space, causing my disk quota on the Uni computer to be exceeded.
To solve those problems, I would like to do the following:
make Jenkins stop rebuilding the old branches. E.g. ignore branches that were last updated more than 2 weeks ago.
Make Jenkins run "deleteDir()" in the post phase of all builds.
I can easily update my Jenkinsfile to achieve these goals. But then I have to put the new Jenkinsfile into every single branch I have! So that's where I'm stuck. I really don't want to have to update every single old branch by hand.
I've had some ideas for solutions, but none of them satisfy me. I could e.g.:
Delete the old branches, but we can't do that, because this is a university module, and all branches should be kept in the repository as a kind of proof that one has been practicing writing code.
Write a script to add the new Jenkinsfile to every single branch in our repo. This would be a kind of weird look. I don't want my name to be in every single branch.
Write a script that fetches all branches from the main repo into a secondary repo, which I would then point the multibranch pipeline at. Then write another script that regularly deletes obsolete branches from this secondary repo. This sounds like so much work!! And it does not solve the issue of running deleteDir() at the end of every build.
Basically, I would like to find a way of reconfiguring my pipeline inside of Jenkins without individually updating the Jenkinsfile in every branch. Is there a way to do this?
Here is my Jenkinsfile, for reference. Could it be that I have to adapt it to be used in a "normal pipeline" rather than a "multibranch pipeline"?
def commitHash
pipeline {
agent any
triggers {
// Every branch should be rebuilt after developer is built
// This doesn't cause an infinite loop, because 'Developer builden' is a job that only specifically
// gets triggered after a commit is pushed to developer. The event will not be fired a second time
// when developer is built as a result of this upstream trigger.
upstream(upstreamProjects: 'Developer builden', threshold: hudson.model.Result.FAILURE)
}
stages {
stage('Build') {
steps {
echo 'checkout scm'
checkout scm
script {
commitHash = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%H'").trim()
}
echo 'merging into origin/developer'
sh 'git merge origin/developer'
echo 'Building..'
}
}
stage('Test') {
steps {
sh 'mvn clean package'
echo 'Testing..'
}
}
stage('Deploy') {
steps {
echo 'Deploying....'
}
}
}
post {
always {
script {
currentBuild.result = currentBuild.result ?: 'SUCCESS'
echo "build result: ${currentBuild.result}"
echo "commitSha1: ${commitHash}"
notifyBitbucket commitSha1: commitHash,
credentialsId: '<redacted>',
disableInprogressNotification: false,
considerUnstableAsSuccess: false,
ignoreUnverifiedSSLPeer: true,
includeBuildNumberInKey: false,
prependParentProjectKey: false,
projectKey: '',
stashServerBaseUrl: '<redacted>'
}
deleteDir() // This line is, unfortunately, not present in most of our older branches.
}
}
}
git version-control jenkins
add a comment |
I have a shared git repository used by 12 people. I want to rebuild every branch after the branch itself gets updated or a PR gets merged into developer.
I configured a multibranch pipeline and wrote a Jenkinsfile that achieves this goal.
This Jenkinsfile is in developer, and it's now been included into more than 60 branches. This was OK at first, but now that we have so many branches, over 60 builds get queued up every time we merge a PR. It can take a very long time for all of those builds to complete. Also, the builds use up a lot of disk space, causing my disk quota on the Uni computer to be exceeded.
To solve those problems, I would like to do the following:
make Jenkins stop rebuilding the old branches. E.g. ignore branches that were last updated more than 2 weeks ago.
Make Jenkins run "deleteDir()" in the post phase of all builds.
I can easily update my Jenkinsfile to achieve these goals. But then I have to put the new Jenkinsfile into every single branch I have! So that's where I'm stuck. I really don't want to have to update every single old branch by hand.
I've had some ideas for solutions, but none of them satisfy me. I could e.g.:
Delete the old branches, but we can't do that, because this is a university module, and all branches should be kept in the repository as a kind of proof that one has been practicing writing code.
Write a script to add the new Jenkinsfile to every single branch in our repo. This would be a kind of weird look. I don't want my name to be in every single branch.
Write a script that fetches all branches from the main repo into a secondary repo, which I would then point the multibranch pipeline at. Then write another script that regularly deletes obsolete branches from this secondary repo. This sounds like so much work!! And it does not solve the issue of running deleteDir() at the end of every build.
Basically, I would like to find a way of reconfiguring my pipeline inside of Jenkins without individually updating the Jenkinsfile in every branch. Is there a way to do this?
Here is my Jenkinsfile, for reference. Could it be that I have to adapt it to be used in a "normal pipeline" rather than a "multibranch pipeline"?
def commitHash
pipeline {
agent any
triggers {
// Every branch should be rebuilt after developer is built
// This doesn't cause an infinite loop, because 'Developer builden' is a job that only specifically
// gets triggered after a commit is pushed to developer. The event will not be fired a second time
// when developer is built as a result of this upstream trigger.
upstream(upstreamProjects: 'Developer builden', threshold: hudson.model.Result.FAILURE)
}
stages {
stage('Build') {
steps {
echo 'checkout scm'
checkout scm
script {
commitHash = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%H'").trim()
}
echo 'merging into origin/developer'
sh 'git merge origin/developer'
echo 'Building..'
}
}
stage('Test') {
steps {
sh 'mvn clean package'
echo 'Testing..'
}
}
stage('Deploy') {
steps {
echo 'Deploying....'
}
}
}
post {
always {
script {
currentBuild.result = currentBuild.result ?: 'SUCCESS'
echo "build result: ${currentBuild.result}"
echo "commitSha1: ${commitHash}"
notifyBitbucket commitSha1: commitHash,
credentialsId: '<redacted>',
disableInprogressNotification: false,
considerUnstableAsSuccess: false,
ignoreUnverifiedSSLPeer: true,
includeBuildNumberInKey: false,
prependParentProjectKey: false,
projectKey: '',
stashServerBaseUrl: '<redacted>'
}
deleteDir() // This line is, unfortunately, not present in most of our older branches.
}
}
}
git version-control jenkins
I have a shared git repository used by 12 people. I want to rebuild every branch after the branch itself gets updated or a PR gets merged into developer.
I configured a multibranch pipeline and wrote a Jenkinsfile that achieves this goal.
This Jenkinsfile is in developer, and it's now been included into more than 60 branches. This was OK at first, but now that we have so many branches, over 60 builds get queued up every time we merge a PR. It can take a very long time for all of those builds to complete. Also, the builds use up a lot of disk space, causing my disk quota on the Uni computer to be exceeded.
To solve those problems, I would like to do the following:
make Jenkins stop rebuilding the old branches. E.g. ignore branches that were last updated more than 2 weeks ago.
Make Jenkins run "deleteDir()" in the post phase of all builds.
I can easily update my Jenkinsfile to achieve these goals. But then I have to put the new Jenkinsfile into every single branch I have! So that's where I'm stuck. I really don't want to have to update every single old branch by hand.
I've had some ideas for solutions, but none of them satisfy me. I could e.g.:
Delete the old branches, but we can't do that, because this is a university module, and all branches should be kept in the repository as a kind of proof that one has been practicing writing code.
Write a script to add the new Jenkinsfile to every single branch in our repo. This would be a kind of weird look. I don't want my name to be in every single branch.
Write a script that fetches all branches from the main repo into a secondary repo, which I would then point the multibranch pipeline at. Then write another script that regularly deletes obsolete branches from this secondary repo. This sounds like so much work!! And it does not solve the issue of running deleteDir() at the end of every build.
Basically, I would like to find a way of reconfiguring my pipeline inside of Jenkins without individually updating the Jenkinsfile in every branch. Is there a way to do this?
Here is my Jenkinsfile, for reference. Could it be that I have to adapt it to be used in a "normal pipeline" rather than a "multibranch pipeline"?
def commitHash
pipeline {
agent any
triggers {
// Every branch should be rebuilt after developer is built
// This doesn't cause an infinite loop, because 'Developer builden' is a job that only specifically
// gets triggered after a commit is pushed to developer. The event will not be fired a second time
// when developer is built as a result of this upstream trigger.
upstream(upstreamProjects: 'Developer builden', threshold: hudson.model.Result.FAILURE)
}
stages {
stage('Build') {
steps {
echo 'checkout scm'
checkout scm
script {
commitHash = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%H'").trim()
}
echo 'merging into origin/developer'
sh 'git merge origin/developer'
echo 'Building..'
}
}
stage('Test') {
steps {
sh 'mvn clean package'
echo 'Testing..'
}
}
stage('Deploy') {
steps {
echo 'Deploying....'
}
}
}
post {
always {
script {
currentBuild.result = currentBuild.result ?: 'SUCCESS'
echo "build result: ${currentBuild.result}"
echo "commitSha1: ${commitHash}"
notifyBitbucket commitSha1: commitHash,
credentialsId: '<redacted>',
disableInprogressNotification: false,
considerUnstableAsSuccess: false,
ignoreUnverifiedSSLPeer: true,
includeBuildNumberInKey: false,
prependParentProjectKey: false,
projectKey: '',
stashServerBaseUrl: '<redacted>'
}
deleteDir() // This line is, unfortunately, not present in most of our older branches.
}
}
}
git version-control jenkins
git version-control jenkins
asked Jan 26 at 14:53
AnnAnn
1
1
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1398726%2fhow-can-i-reconfigure-a-multibranch-pipeline-in-jenkins-without-changing-the-jen%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Super User!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1398726%2fhow-can-i-reconfigure-a-multibranch-pipeline-in-jenkins-without-changing-the-jen%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown