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

Automatizuoti naujų projektų kūrimą Jenkins pusėje #6

Open
aurelijusb opened this issue Nov 11, 2018 · 0 comments
Open

Automatizuoti naujų projektų kūrimą Jenkins pusėje #6

aurelijusb opened this issue Nov 11, 2018 · 0 comments

Comments

@aurelijusb
Copy link
Member

Problema

Su kiekvienu semestru reikia paruošti CI serverį projektų sukėlimui į LIVE (NFQ akademijos WEB serverį).
Rankomis tai užima daug laiko ir įvelia neatidumo klaidų.

Siūlomas sprendimas

Daugumą vietų galima automatizuoti.
Pvz. su Groovy skriptu per Manage Jenkins->Script Console

Kliūtys

Sunku sujungti naudotojų kūrimą, jų teises, FreeStyleProject ir GitHub/Slack įskiepių pajungimą.
Mažai dokumentacijos ir gali užtrukti ilgiau nei kartą per semestrą sukurti rankomis.

Susijusi medžiaga

https://gist.github.com/hayderimran7/50cb1244cc1e856873a4
https://javadoc.jenkins.io/hudson/security/HudsonPrivateSecurityRealm.html
https://gist.github.com/aespinosa/6bd1b8d2d65aed2179de
https://javadoc.jenkins.io/hudson/model/FreeStyleProject.html
https://support.cloudbees.com/hc/en-us/articles/215549798-Deleting-Old-Builds-Best-Strategy-for-Cleanup-and-disk-space-management
https://github.com/glenjamin/jenkins-groovy-examples/blob/master/README.md

Susiję pavyzdžiai

import jenkins.model.*
def instance = Jenkins.getInstance()

roles = instance.authorizationStrategy.getRoleMap('projectRoles').getRoles()

for (r in roles) {
  println "${r.getName()}: ${r.getPattern()}: ${r.getPermissions()}"
}
import jenkins.model.Jenkins
import hudson.security.*
import hudson.plugins.git.GitSCM;
import hudson.plugins.git.BranchSpec;
import org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition;
import hudson.model.FreeStyleProject;
import hudson.tasks.Shell;
import jenkins.model.BuildDiscarderProperty
import hudson.tasks.LogRotator

user = "test20181015"
attemp = "15"

def instance = Jenkins.getInstance()
def hudsonRealm = new HudsonPrivateSecurityRealm(false)
hudsonRealm.createAccount("aurelijus-test-2018-11-11-${attemp}","UPDATE_PASSWORD_HERE!!!!!!!!!!!!")
instance.setSecurityRealm(hudsonRealm)


githubPath = "https://github.com/nfqakademija/${user}.git/"
branchPattern = "*/master"
jobName = "${user}-test-${attemp}"
shellScript = '''
$WORKSPACE/.deploy/build.sh
echo "[app]
nfqakademija.lt ansible_host=deploy.nfqakademija.lt ansible_user=$JOB_NAME
" > $WORKSPACE/.deploy/ansible_hosts
$WORKSPACE/.deploy/deploy.sh
'''

println "Creating Project ${user}"
println "  Using Git repository: ${githubPath}"
println "  Build triggered for branches: ${branchPattern}"
println "  Using job name: ${jobName}"

scm = new GitSCM("https://github.com/nfqakademija/${user}.git/");
scm.branches = [new BranchSpec(branchPattern)];

job = instance.createProject(FreeStyleProject, jobName)
job.setScm(scm)
job.addProperty(new BuildDiscarderProperty(new LogRotator(15, 10, 15, 10)))
job.getBuildersList().add(new Shell(shellScript));

job.save()

instance.save()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant