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

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

Yasuhiroki
November 08, 2017

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

第11回 Jenkins勉強会 LT

Yasuhiroki

November 08, 2017
Tweet

More Decks by Yasuhiroki

Other Decks in Technology

Transcript

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  4. ࢲͷࢲʹΑΔࢲͷͨΊͷJenkins
    • ผʹࣗ෼Ͱ΍ͬͯ΋ྑ͍Μ͚ͩͲɺ

    ୅ΘΓʹ΍ͬͯ͘ΕΔͳΒॿ͔Δ࡞ۀ
    • ۀ຿ͱͯࣗ͠ಈԽ͢Δ΄ͲͰ΋ͳ͍͚Ͳɺ

    ࣗಈԽͤͣʹ͸͍ΒΕͳ͔ͬͨ࡞ۀ
    • ༡ͼ

    View full-size slide

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

    View full-size slide

  6. ࣥࣄޏ༻ܭը

    View full-size slide

  7. ࣥࣄ͸࢖͍ࣺͯ

    View full-size slide

  8. ඞཁͳ࣌ʹޏ͍

    ඞཁͷͳ͍࣌͸ղޏ͢Δ

    View full-size slide

  9. Jenkinsͷߏங

    View full-size slide

  10. ࢲͷͨΊͷJenkins͔ͩΒ

    ࢲͷ޷͖ͳΑ͏ʹߏங͢Δ

    View full-size slide

  11. 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 ΋͋Δ

    View full-size slide

  12. Jenkinsͷߏங͸GitHubͰ؅ཧ
    • docker-compose
    • docker-compose.yml Λ GitHub Ͱ؅ཧ

    View full-size slide

  13. ΧελϚΠζ͸DockerfileͰ
    • Dockerfile
    • ࢲͷͨΊͷJenkinsͷॳظߏங
    • ࣗ෼༻ͷ Docker ΠϝʔδΛ DockerHub ʹ push ͯ͠΋ྑ͍
    • ࣗ෼ͷࣥࣄ͕ଞॴͰಇ͍ͯ΋ࣧౄ͠ͳ͍ਓʹݶΔ
    • ͋Β͔͡Ί༻ҙ͞Ε͍ͯΔػೳΛ࢖͑͹ɺ

    DockerΠϝʔδΛ༻ҙ͠ͳͯ͘΋͋Δఔ౓ಈతʹߏஙͰ͖Δ

    View full-size slide

  14. *.override
    • ެࣜJenkins Docker ͷػೳ
    • config.xml.override ͳͲͱ༻ҙͨ͠ϑΝΠϧͰɺίϯς
    φىಈ࣌ʹݩͷϑΝΠϧʹ্ॻ͖͢Δ
    • ڧͯ͘χϡʔήʔϜͰ͖Δ

    View full-size slide

  15. install-plugin.sh
    • ެࣜJenkins Docker ͷػೳ
    • Πϯετʔϧ͍ͨ͠ plugin ͷҰཡΛॻ͍ͨϑΝΠϧΛ৯
    ΘͤΔͱɺίϯςφىಈ࣌ʹ ґଘ͢Δ plugin ΋ؚΊͯΠ
    ϯετʔϧͯ͘͠ΕΔ
    • όʔδϣϯࢦఆ΋Մೳ

    View full-size slide

  16. -Djenkins.install.runSetupWizard=false
    • Jenkinsىಈ࣌ʹ౉͢JAVA_OPT
    • ॳճىಈ࣌ʹग़ͯ͘ΔɺΦεεϝϓϥάΠϯͷΠϯετʔ
    ϧ΍ηΩϡϦςΟઃఆͳͲΛεΩοϓͰ͖Δ
    • ࢲͷࢲʹΑΔࢲͷͨΊͷJenkinsʹ͸ෆཁͳͷͰઃఆ͢Δ

    View full-size slide

  17. Jenkinsδϣϒͷ؅ཧ

    View full-size slide

  18. ࢲͷͨΊͷJenkins͔ͩΒ

    ࢲ͕ϝϯςͰ͖Ε͹͍͍

    View full-size slide

  19. GitHub Organization Plugin
    • Multibranch Pipeline ͷ GitHub ಛԽ൛
    • ࣗ෼ͷΞΧ΢ϯτΛࢦఆ͢Δ͚ͩͰɺJenkinsfile Λ࣋ͭ
    ϦϙδτϦΛݕग़ͯ͠উखʹϏϧυͯ͘͠ΕΔ
    • ࠓճ͸ https://github.com/yasuhiroki/myJenkinsfile ͚ͩ
    Λݕग़͢ΔΑ͏ʹઃఆ

    View full-size slide

  20. δϣϒ = ϒϥϯν
    • jobs/* ͱ͍͏໊લͷϒϥϯν͕ɺJenkinsͷδϣϒʹͳΔ
    Α͏ઃఆ͢Δ
    • jobs/sendo, jobs/today-is ͳͲɺδϣϒຖʹϒϥϯνΛ࡞
    Δ

    View full-size slide

  21. git worktree ίϚϯυ
    • δϣϒ͝ͱʹ͍͍ͪͪ checkout ͢Δͷ͸໘౗ͳͷͰɺ

    git worktree ίϚϯυΛར༻͢Δ
    • git worktree add jobs/today-is jobs/today-is ͱ͢Δͱɺ

    jobs/today-is σΟϨΫτϦʹ jobs/today-is ϒϥϯν͕
    νΣοΫΞ΢τ͞ΕΔ
    • ϒϥϯνͷ਺͚ͩσΟϨΫτϦΛ࡞ͬͯ checkout ͢Ε͹ɺ

    δϣϒͷઃఆ͕ू·ͬͨ jobs σΟϨΫτϦͷͰ͖͕͋Γ

    View full-size slide

  22. Jenkinsfile
    • ࢲͷͨΊͷࣥࣄΛޏ͏ʹ͸ Jenkinsfile ͕ඞਢ
    • https://jenkins.io/doc/book/pipeline/syntax/ ͸ࣥࣄޏ༻
    ϚχϡΞϧ

    View full-size slide

  23. ϊʔυͷ؅ཧ

    View full-size slide

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

    View full-size slide

  25. Docker Pipeline plugin
    • JenkinsfileͰϏϧυΛ࣮ߦ͍ͨ͠ docker image Λࢦఆ͢
    Δ
    • Jenkinsίϯςφͱಉ͡ docker.sock Λ࢖͏Α͏ઃఆ͢Ε
    ͹ɺJenkinsίϯςφࣗମ΋৮ΕΔ
    • ༡ͼϙΠϯτ
    • ྫɿࣥࣄةػҰ൅ήʔϜ

    View full-size slide

  26. jenkinsci/jnlp-slave
    • ϊʔυ༻ίϯςφΛىಈ͠JenkinsʹJNLPͰ઀ଓ͢Δ
    • ࣥࣄΛαϙʔτ͢ΔϝΠυతଘࡏ
    • େྔʹ༻ҙͯ͠ϝΠυୂΛ࡞Δͷ͕Φεεϝ
    • δϣϒͷϏϧυ͸Docker PipelineͰࣄ଍ΓΔͷͰɺ

    ϝΠυ͞Μͱ༡Ϳ͜ͱʹूத͢Δ͜ͱ

    View full-size slide

  27. jenkinsci/jnlp-slave
    • *.override ͷػೳΛ࢖ͬͯɺࣄલʹϊʔυͷ৘ใΛ
    Jenkinsʹ༻ҙ͓ͯ͘͠ͱॳظߏஙΛ΄΅ࣗಈԽͰ͖Δ
    • secret τʔΫϯ͸Ұ౓࡞ΒΕͨΒ JENKINS_HOME ҎԼ
    Λ࡞Γ௚͞ͳ͍ݶΓಉ͡ͳͷͰࣗಈԽͰ͖Δ
    • ॳճ͚ͩ͸खಈͰొ࿥͕ඞཁ
    • groovy ͰΰϦΰϦ΍Ε͹׬શࣗಈԽͰ͖Δؾ͕͢Δ

    View full-size slide

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

    Chef ΍ Ansible ͰΰϦΰϦ͠ͳͯ͘΋ɺ

    ΦϨΦϨεΫϦϓτͰΰϦΰϦ͠ͳͯ͘΋ɺ

    ͋Δఔ౓ɺ࠶ߏஙՄೳͳJenkins؀ڥ͕खʹೖΔ

    ɹ˞ ͨͩ͠ Docker ͷ஌͕ࣝඞཁ
    • Ͱ͖Δ͚ͩJenkinsຊମͷઃఆΛݮΒ͢ͷ͕େࣄ

    View full-size slide