Upgrade to Pro — share decks privately, control downloads, hide ads and more …

開発者(個人)のためのJenkins 運用編

D504d1f14dd00f8028c440e9d1923d37?s=47 Yasuhiroki
November 08, 2017

開発者(個人)のためのJenkins 運用編

第11回 Jenkins勉強会 LT

D504d1f14dd00f8028c440e9d1923d37?s=128

Yasuhiroki

November 08, 2017
Tweet

Transcript

  1. ։ൃऀ(ݸਓ)ͷͨΊͷ Jenkins ӡ༻ฤ @yasuhiroki

  2. @yasuhiroki

  3. https://certificates.cloudbees.com/10203903

  4. ։ൃऀ(ݸਓ)ͷͨΊͷJenkins

  5. ࢲͷࢲʹΑΔࢲͷͨΊͷJenkins • ผʹࣗ෼Ͱ΍ͬͯ΋ྑ͍Μ͚ͩͲɺ
 ୅ΘΓʹ΍ͬͯ͘ΕΔͳΒॿ͔Δ࡞ۀ • ۀ຿ͱͯࣗ͠ಈԽ͢Δ΄ͲͰ΋ͳ͍͚Ͳɺ
 ࣗಈԽͤͣʹ͸͍ΒΕͳ͔ͬͨ࡞ۀ • ༡ͼ

  6. ޾ͤͳੜ׆ ࠓ೔͸ૉ਺͔ɺφϕΞπ͔Λڭ͑ͯ͘ΕΔࣥࣄ

  7. ࣥࣄޏ༻ܭը

  8. ࣥࣄ͸࢖͍ࣺͯ

  9. ඞཁͳ࣌ʹޏ͍
 ඞཁͷͳ͍࣌͸ղޏ͢Δ

  10. Jenkinsͷߏங

  11. ࢲͷͨΊͷJenkins͔ͩΒ
 ࢲͷ޷͖ͳΑ͏ʹߏங͢Δ

  12. DockerͰJenkinsΛىಈ͢Δ • Docker • https://hub.docker.com/_/jenkins/ Ͱ͸ͳ͘ • https://hub.docker.com/r/jenkinsci/jenkins/ Ͱ΋ͳ͘ •

    https://hub.docker.com/r/jenkins/jenkins/ ͚ͩͲ • https://store.docker.com/images/jenkins ΋͋Δ
  13. Jenkinsͷߏங͸GitHubͰ؅ཧ • docker-compose • docker-compose.yml Λ GitHub Ͱ؅ཧ

  14. ΧελϚΠζ͸DockerfileͰ • Dockerfile • ࢲͷͨΊͷJenkinsͷॳظߏங • ࣗ෼༻ͷ Docker ΠϝʔδΛ DockerHub

    ʹ push ͯ͠΋ྑ͍ • ࣗ෼ͷࣥࣄ͕ଞॴͰಇ͍ͯ΋ࣧౄ͠ͳ͍ਓʹݶΔ • ͋Β͔͡Ί༻ҙ͞Ε͍ͯΔػೳΛ࢖͑͹ɺ
 DockerΠϝʔδΛ༻ҙ͠ͳͯ͘΋͋Δఔ౓ಈతʹߏஙͰ͖Δ
  15. *.override • ެࣜJenkins Docker ͷػೳ • config.xml.override ͳͲͱ༻ҙͨ͠ϑΝΠϧͰɺίϯς φىಈ࣌ʹݩͷϑΝΠϧʹ্ॻ͖͢Δ •

    ڧͯ͘χϡʔήʔϜͰ͖Δ
  16. install-plugin.sh • ެࣜJenkins Docker ͷػೳ • Πϯετʔϧ͍ͨ͠ plugin ͷҰཡΛॻ͍ͨϑΝΠϧΛ৯ ΘͤΔͱɺίϯςφىಈ࣌ʹ

    ґଘ͢Δ plugin ΋ؚΊͯΠ ϯετʔϧͯ͘͠ΕΔ • όʔδϣϯࢦఆ΋Մೳ
  17. -Djenkins.install.runSetupWizard=false • Jenkinsىಈ࣌ʹ౉͢JAVA_OPT • ॳճىಈ࣌ʹग़ͯ͘ΔɺΦεεϝϓϥάΠϯͷΠϯετʔ ϧ΍ηΩϡϦςΟઃఆͳͲΛεΩοϓͰ͖Δ • ࢲͷࢲʹΑΔࢲͷͨΊͷJenkinsʹ͸ෆཁͳͷͰઃఆ͢Δ

  18. Jenkinsδϣϒͷ؅ཧ

  19. ࢲͷͨΊͷJenkins͔ͩΒ
 ࢲ͕ϝϯςͰ͖Ε͹͍͍

  20. GitHub Organization Plugin • Multibranch Pipeline ͷ GitHub ಛԽ൛ •

    ࣗ෼ͷΞΧ΢ϯτΛࢦఆ͢Δ͚ͩͰɺJenkinsfile Λ࣋ͭ ϦϙδτϦΛݕग़ͯ͠উखʹϏϧυͯ͘͠ΕΔ • ࠓճ͸ https://github.com/yasuhiroki/myJenkinsfile ͚ͩ Λݕग़͢ΔΑ͏ʹઃఆ
  21. δϣϒ = ϒϥϯν • jobs/* ͱ͍͏໊લͷϒϥϯν͕ɺJenkinsͷδϣϒʹͳΔ Α͏ઃఆ͢Δ • jobs/sendo, jobs/today-is

    ͳͲɺδϣϒຖʹϒϥϯνΛ࡞ Δ
  22. git worktree ίϚϯυ • δϣϒ͝ͱʹ͍͍ͪͪ checkout ͢Δͷ͸໘౗ͳͷͰɺ
 git worktree ίϚϯυΛར༻͢Δ

    • git worktree add jobs/today-is jobs/today-is ͱ͢Δͱɺ
 jobs/today-is σΟϨΫτϦʹ jobs/today-is ϒϥϯν͕ νΣοΫΞ΢τ͞ΕΔ • ϒϥϯνͷ਺͚ͩσΟϨΫτϦΛ࡞ͬͯ checkout ͢Ε͹ɺ
 δϣϒͷઃఆ͕ू·ͬͨ jobs σΟϨΫτϦͷͰ͖͕͋Γ
  23. Jenkinsfile • ࢲͷͨΊͷࣥࣄΛޏ͏ʹ͸ Jenkinsfile ͕ඞਢ • https://jenkins.io/doc/book/pipeline/syntax/ ͸ࣥࣄޏ༻ ϚχϡΞϧ

  24. ϊʔυͷ؅ཧ

  25. ϊʔυͷ؅ཧ͸2ύλʔϯ • Docker Pipeline plugin • jenkinsci/jnlp-slave Docker Πϝʔδ

  26. Docker Pipeline plugin • JenkinsfileͰϏϧυΛ࣮ߦ͍ͨ͠ docker image Λࢦఆ͢ Δ •

    Jenkinsίϯςφͱಉ͡ docker.sock Λ࢖͏Α͏ઃఆ͢Ε ͹ɺJenkinsίϯςφࣗମ΋৮ΕΔ • ༡ͼϙΠϯτ • ྫɿࣥࣄةػҰ൅ήʔϜ
  27. jenkinsci/jnlp-slave • ϊʔυ༻ίϯςφΛىಈ͠JenkinsʹJNLPͰ઀ଓ͢Δ • ࣥࣄΛαϙʔτ͢ΔϝΠυతଘࡏ • େྔʹ༻ҙͯ͠ϝΠυୂΛ࡞Δͷ͕Φεεϝ • δϣϒͷϏϧυ͸Docker PipelineͰࣄ଍ΓΔͷͰɺ


    ϝΠυ͞Μͱ༡Ϳ͜ͱʹूத͢Δ͜ͱ
  28. jenkinsci/jnlp-slave • *.override ͷػೳΛ࢖ͬͯɺࣄલʹϊʔυͷ৘ใΛ Jenkinsʹ༻ҙ͓ͯ͘͠ͱॳظߏஙΛ΄΅ࣗಈԽͰ͖Δ • secret τʔΫϯ͸Ұ౓࡞ΒΕͨΒ JENKINS_HOME ҎԼ

    Λ࡞Γ௚͞ͳ͍ݶΓಉ͡ͳͷͰࣗಈԽͰ͖Δ • ॳճ͚ͩ͸खಈͰొ࿥͕ඞཁ • groovy ͰΰϦΰϦ΍Ε͹׬શࣗಈԽͰ͖Δؾ͕͢Δ
  29. ·ͱΊ

  30. JenkinsΛͰ͖Δ͚ͩImmutableͯ͠Έͨ • DockerͱGitHubͱJenkinsfileͰ͋Δఔ౓ImmutableʹͰ͖Δ • GroovyεΫϦϓτͰΰϦΰϦ͠ͳͯ͘΋ɺ
 Chef ΍ Ansible ͰΰϦΰϦ͠ͳͯ͘΋ɺ
 ΦϨΦϨεΫϦϓτͰΰϦΰϦ͠ͳͯ͘΋ɺ


    ͋Δఔ౓ɺ࠶ߏஙՄೳͳJenkins؀ڥ͕खʹೖΔ
 ɹ˞ ͨͩ͠ Docker ͷ஌͕ࣝඞཁ • Ͱ͖Δ͚ͩJenkinsຊମͷઃఆΛݮΒ͢ͷ͕େࣄ
  31. FIN