Skip to content

Commit

Permalink
feat: jenkins casc + seed job
Browse files Browse the repository at this point in the history
  • Loading branch information
karanwadhwa authored and sydrawat01 committed Oct 20, 2023
1 parent 5191f37 commit b0747f9
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 16 deletions.
35 changes: 19 additions & 16 deletions scripts/casc.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
obs:
- script: >
multibranchPipelineJob('test-seed') {
branchSources {
git {
id('92098798334')
remote('https://github.com/username/example')
includes('*')
}
}
orphanedItemStrategy {
discardOldItems {
numToKeep(5)
}
}
}
jenkins:
systemMessage: "Jenkins configured automatically by Jenkins Configuration as Code Plugin\n\n"

jobs:
- file: ./jenkins_setup.groovy

credentials:
system:
domainCredentials:
- credentials:
- gitHubApp:
appID: "1111"
description: "GitHub app"
id: "github-app"
# apiUri: https://my-custom-github-enterprise.com/api/v3 # optional only required for GitHub enterprise
privateKey: |
"-----BEGIN PRIVATE KEY-----
-----END PRIVATE KEY-----"
80 changes: 80 additions & 0 deletions scripts/jenkins_setup.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
organizationFolder("GitHub organization") {
displayName("GitHub organization")
description("GitHub organization")
organizations {
github {
repoOwner("csye7125-fall2023-group05")
scanCredentialsId("github-organization-credentials")
apiUri("https://api.github.com")


configure { node ->
def traits = node / navigators / 'org.jenkinsci.plugins.github_branch_source.GitHubSCMNavigator' / traits

// Discover branches
// https://javadoc.jenkins.io/plugin/github-branch-source/org/jenkinsci/plugins/github_branch_source/BranchDiscoveryTrait.html
traits << 'org.jenkinsci.plugins.github__branch__source.BranchDiscoveryTrait' {
strategyId('1')
// Values
// 1: Exclude branches that are also filed as PRs
// 2: Only branches that are also filed as PRs
// 3: All branches
//
}

// Discover pull requests from origin
// https://javadoc.jenkins.io/plugin/github-branch-source/org/jenkinsci/plugins/github_branch_source/OriginPullRequestDiscoveryTrait.html
traits << 'org.jenkinsci.plugins.github_branch_source.OriginPullRequestDiscoveryTrait' {
strategyId('2')
// Values
// 1. Merging the pull request with the current target branch revision
// 2. The current pull request revision
// 3. Both the current pull request revision and the pull request merged with the current target branch revision
}

// Discover pull requests from forks
// https://javadoc.jenkins.io/plugin/github-branch-source/org/jenkinsci/plugins/github_branch_source/ForkPullRequestDiscoveryTrait.html
traits << 'org.jenkinsci.plugins.github_branch_source.ForkPullRequestDiscoveryTrait' {
// Strategy
strategyId('2')
// Values
// 1. Merging the pull request with the current target branch revision
// 2. The current pull request revision
// 3. Both the current pull request revision and the pull request merged with the current target branch revision

// Trust
trustId('4')
// Values
// 1. No trust
// 2. Collaborators
// 3. Everyone
// 4. From users with Admin or Write permission
}
}
}
// Project Recognizers
projectFactories {
workflowMultiBranchProjectFactory {
scriptPath 'Jenkinsfile'
}
}

// TODO: Property Strategy

// Orphaned Item Strategy
orphanedItemStrategy {
discardOldItems {
daysToKeep(-1)
numToKeep(-1)
}
}

// Scan Organization Folder Triggers: 1 day
configure { node ->
node / triggers / 'com.cloudbees.hudson.plugins.folder.computed.PeriodicFolderTrigger' {
spec('H H * * *')
interval(86400000)
}
}
}
}

0 comments on commit b0747f9

Please sign in to comment.