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

Org folder job #26

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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-----"
10 changes: 9 additions & 1 deletion scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ echo "|
echo "+-----------------------------------------------------------------------------------------------------------------------------------------+"

# Install Jenkins plugin manager tool:
wget https://github.com/jenkinsci/plugin-installation-manager-tool/releases/download/2.12.13/jenkins-plugin-manager-2.12.13.jar
wget --quiet \
https://github.com/jenkinsci/plugin-installation-manager-tool/releases/download/2.12.13/jenkins-plugin-manager-2.12.13.jar

# Install plugins with jenkins-plugin-manager tool:
sudo java -jar ./jenkins-plugin-manager-2.12.13.jar --war /usr/share/java/jenkins.war \
Expand All @@ -139,6 +140,13 @@ sudo java -jar ./jenkins-plugin-manager-2.12.13.jar --war /usr/share/java/jenkin
cd /var/lib/jenkins/plugins/ || exit
sudo chown jenkins:jenkins *

# Move casc.yaml file to Jenkins home
sudo mv /home/ubuntu/casc.yaml /var/lib/jenkins/casc.yaml
sudo mv /home/ubuntu/jenkins_setup.groovy /var/lib/jenkins/jenkins_setup.groovy
# Update file ownership
sudo chown jenkins:jenkins /var/lib/jenkins/casc.yaml
sudo chown jenkins:jenkins /var/lib/jenkins/jenkins_setup.groovy

# Configure JAVA_OPTS to disable setup wizard
sudo mkdir -p /etc/systemd/system/jenkins.service.d/
{
Expand Down
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)
}
}
}
}
15 changes: 10 additions & 5 deletions ubuntu.ami.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,16 @@ build {
destination = "/home/ubuntu/plugins.txt"
}

provisioner "file" {
source = "./scripts/casc.yaml"
destination = "/home/ubuntu/casc.yaml"
}

provisioner "file" {
source = "./scripts/jenkins_setup.groovy"
destination = "/home/ubuntu/jenkins_setup.groovy"
}

provisioner "shell" {
environment_vars = [
"DEBIAN_FRONTEND=noninteractive",
Expand All @@ -141,11 +151,6 @@ build {
]
}

provisioner "file" {
source = "./scripts/casc.yaml"
destination = "/var/lib/jenkins/casc.yaml"
}

post-processor "manifest" {
output = "manifest.json"
strip_path = true
Expand Down