Last active
November 4, 2020 20:49
-
-
Save nocode99/d4c654514ff2b683af90d7dd5e0156e0 to your computer and use it in GitHub Desktop.
Jenkins Job-DSL Folder for Shared Pipeline config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
folder('My_folder') { | |
properties { | |
folderLibraries { | |
libraries { | |
libraryConfiguration { | |
name('shared-pipeline') | |
defaultVersion('master') | |
implicit(false) | |
allowVersionOverride(true) | |
includeInChangesets(true) | |
retriever { | |
scmSourceRetriever { | |
scm { | |
git { | |
remote('ssh://git@github.com/org/shared-pipeline.git') | |
credentialsId('some-credentials') | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
configure { node -> | |
node / properties / 'org.jenkinsci.plugins.workflow.libs.FolderLibraries' / libraries / 'org.jenkinsci.plugins.workflow.libs.LibraryConfiguration' / retriever / scm / traits { | |
'jenkins.plugins.git.traits.BranchDiscoveryTrait'() | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version='1.1' encoding='UTF-8'?> | |
<com.cloudbees.hudson.plugins.folder.Folder plugin="cloudbees-folder@6.7"> | |
<actions/> | |
<description></description> | |
<properties> | |
<org.jenkinsci.plugins.workflow.libs.FolderLibraries plugin="workflow-cps-global-lib@2.13"> | |
<libraries> | |
<org.jenkinsci.plugins.workflow.libs.LibraryConfiguration> | |
<name>shared-pipeline</name> | |
<retriever class="org.jenkinsci.plugins.workflow.libs.SCMSourceRetriever"> | |
<scm class="jenkins.plugins.git.GitSCMSource" plugin="git@3.9.3"> | |
<id>unique-id</id> | |
<remote>ssh://git@github.com/org/shared-pipeline.git</remote> | |
<credentialsId>some-credentials</credentialsId> | |
<traits> | |
<jenkins.plugins.git.traits.BranchDiscoveryTrait/> // <--- HOW DO I CONFIGURE THIS | |
</traits> | |
</scm> | |
</retriever> |
I ended up doing this:
def scmTrait = { folder ->
folder / 'properties' / 'org.jenkinsci.plugins.workflow.libs.FolderLibraries' / 'libraries' / 'org.jenkinsci.plugins.workflow.libs.LibraryConfiguration' / retriever / scm / traits {
'jenkins.plugins.git.traits.BranchDiscoveryTrait'()
}
}
// and then called the function like below
...
}
configure scmTrait
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @nocode99,
could you solve the problem?
I had to change your code a bit. I'M using the latest git plugin 4.4.1
I hope it helps or maybe it helps someone else.