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

Jenkins Pipeline Dev Tools

Jenkins Pipeline Dev Tools

Алексей Никитин и Фёдор Чемашкин, Dell EMC
В наших проектах сложность задач и требования возросли настолько, что стало сложно развивать Pipeline без смены подходов и средств разработки. Мы расскажем об интеграции с IDE, синтаксических анализаторах и сборке Pipeline в Gradle.

Fedor Chemashkin

February 27, 2018
Tweet

Other Decks in Programming

Transcript

  1. © Copyright 2018 Dell Inc. 2 About us • Alexey

    Nikitin – Elastic Cloud Storage
  2. © Copyright 2018 Dell Inc. 3 About us • Alexey

    Nikitin – Elastic Cloud Storage • Fedor Chemaskin – Elastic Cloud Storage
  3. © Copyright 2018 Dell Inc. 8 Our pipelines An overview

    • Scripted pipelines • Small shared library for our custom loader
  4. © Copyright 2018 Dell Inc. 9 Our pipelines An overview

    • Scripted pipelines • Small shared library for our custom loader • Standards plugins. For our needs - Robot Framework and JUnit plugin
  5. © Copyright 2018 Dell Inc. 10 Our pipelines An overview

    • Scripted pipelines • Small shared library for our custom loader • Standards plugins. For our needs - Robot Framework and JUnit plugin • CI/CD and Automation
  6. © Copyright 2018 Dell Inc. 13 Static analysis For what?

    • Detecting errors on early stage (before using Jenkins for launch)
  7. © Copyright 2018 Dell Inc. 14 Static analysis For what?

    • Detecting errors on early stage (before using Jenkins for launch) • Get recommendations on code formatting (with our code style)
  8. © Copyright 2018 Dell Inc. 15 Static analysis For what?

    • Detecting errors on early stage (before using Jenkins for launch) • Get recommendations on code formatting (with our code style) • Metrics
  9. © Copyright 2018 Dell Inc. 19 Static analysis Tool selection

    Tool Custom rules HTML report Managing error and warning categories for existing rules Custom rules HTML report Custom rules Jenkins
  10. © Copyright 2018 Dell Inc. 21 Static analysis Codenarc –

    Less Bugs Better Code • Analyzes Groovy code for defects, bad practices, inconsistencies, style issues and more
  11. © Copyright 2018 Dell Inc. 22 Static analysis Codenarc –

    Less Bugs Better Code • Analyzes Groovy code for defects, bad practices, inconsistencies, style issues and more • Set of Rules (predefined and/or custom) that are applied to each Groovy file* * - сan be configured
  12. © Copyright 2018 Dell Inc. 25 Static analysis Codenarc –

    Report • Reports come in HTML, XML or text format
  13. © Copyright 2018 Dell Inc. 29 Static analysis Codenarc –

    Integration • Codenarc CLI • Plugins for:
  14. © Copyright 2018 Dell Inc. 30 Static analysis Codenarc –

    Integration • Codenarc CLI • Plugins for: – Maven – Gradle – Grails – ... – Hudson
  15. © Copyright 2018 Dell Inc. 32 Static analysis Codenarc –

    Jenkins Integration • Hudson Violations Plugin is not maintained
  16. © Copyright 2018 Dell Inc. 33 Static analysis Codenarc –

    Jenkins Integration • Hudson Violations Plugin is not maintained • Jenkins Warning plugin
  17. © Copyright 2018 Dell Inc. 34 Static analysis Codenarc –

    Jenkins Integration • Hudson Violations Plugin is not maintained • Jenkins Warning plugin • JENKINS-45930 java.io.NotSerializableException: hudson.plugins.violations.types.codenarc.CodenarcParser at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1183)
  18. © Copyright 2018 Dell Inc. 36 Static analysis Codenarc –

    Jenkins Integration workaround Main job
  19. © Copyright 2018 Dell Inc. 37 Static analysis Codenarc –

    Jenkins Integration workaround Main job CI for pipelines (including Codenarc run)
  20. © Copyright 2018 Dell Inc. 38 Static analysis Codenarc –

    Jenkins Integration workaround Main job CI for pipelines (including Codenarc run)
  21. © Copyright 2018 Dell Inc. 39 Static analysis Codenarc –

    Jenkins Integration workaround Main job Freestyle job CI for pipelines (including Codenarc run) XML report
  22. © Copyright 2018 Dell Inc. 40 Static analysis Codenarc –

    Jenkins Integration workaround Running on the master Warning plugin in “Post-build Actions“ sed -i "s/Package path=''/Package path='pipelines'/“ xmlReportName.xml Main job Freestyle job CI for pipelines (including Codenarc run) XML report
  23. © Copyright 2018 Dell Inc. 42 Static analysis Our code

    style • Based on Groovy Style with a few changes
  24. © Copyright 2018 Dell Inc. 43 Static analysis Our code

    style • Based on Groovy Style with a few changes • Strongly typed
  25. © Copyright 2018 Dell Inc. 44 Static analysis Our code

    style • Based on Groovy Style with a few changes • Strongly typed • «Pipelines DSL != Groovy» (с) Oleg Nenashev
  26. © Copyright 2018 Dell Inc. 45 Static analysis Our code

    style • Based on Groovy Style with a few changes • Strongly typed • «Pipelines DSL != Groovy» (с) Oleg Nenashev • Turn-off some Codenarc rules (e.g. Println, design patterns rules)
  27. © Copyright 2018 Dell Inc. 46 Static analysis Our code

    style • Based on Groovy Style with a few changes • Strongly typed • «Pipelines DSL != Groovy» (с) Oleg Nenashev • Turn-off some Codenarc rules (e.g. Println, design patterns rules)
  28. © Copyright 2018 Dell Inc. 47 Static analysis Our code

    style • Based on Groovy Style with a few changes • Strongly typed • «Pipelines DSL != Groovy» (с) Oleg Nenashev • Turn-off some Codenarc rules (e.g. Println, design patterns rules)
  29. © Copyright 2018 Dell Inc. 48 Static analysis Jenkins REST

    API for code validation • Like in “Pipeline” block or “Replay”
  30. IDE

  31. © Copyright 2018 Dell Inc. 54 IDE Requirements • Custom

    Jenkins instructions (e.g. sh, node)
  32. © Copyright 2018 Dell Inc. 55 IDE Requirements • Custom

    Jenkins instructions (e.g. sh, node) • Custom Pipeline libraries methods (e.g. myPerfectLib.buildEverything())
  33. © Copyright 2018 Dell Inc. 56 IDE Requirements • Custom

    Jenkins instructions (e.g. sh, node) • Custom Pipeline libraries methods (e.g. myPerfectLib.buildEverything()) • Groovy syntax
  34. © Copyright 2018 Dell Inc. 57 IDE Requirements • Custom

    Jenkins instructions (e.g. sh, node) • Custom Pipeline libraries methods (e.g. myPerfectLib.buildEverything()) • Groovy syntax • Jenkins classes support (e.g. hudson.model.Run)
  35. © Copyright 2018 Dell Inc. 58 IDE Requirements • Custom

    Jenkins instructions (e.g. sh, node) • Custom Pipeline libraries methods (e.g. myPerfectLib.buildEverything()) • Groovy syntax • Jenkins classes support (e.g. hudson.model.Run) • Codenarc integration
  36. © Copyright 2018 Dell Inc. 59 IDE GDSL • GDSL

    (GroovyDSL) is a feature which enables IDE support for custom DSLs
  37. © Copyright 2018 Dell Inc. 63 IDE IDEA Inspection •

    IntelliJ IDEA performs code analysis by applying inspections to your code
  38. © Copyright 2018 Dell Inc. 64 IDE IDEA Inspection •

    IntelliJ IDEA performs code analysis by applying inspections to your code • The inspections detect not only compiling errors, but also different code inefficiencies:
  39. © Copyright 2018 Dell Inc. 65 IDE IDEA Inspection •

    IntelliJ IDEA performs code analysis by applying inspections to your code • The inspections detect not only compiling errors, but also different code inefficiencies: – unreachable code – unused code – unresolved method – spelling – …
  40. © Copyright 2018 Dell Inc. 66 IDE IDEA Inspection •

    IntelliJ IDEA performs code analysis by applying inspections to your code • The inspections detect not only compiling errors, but also different code inefficiencies: – unreachable code – unused code – unresolved method – spelling – … • Turn-off useless and disturbing inspections
  41. © Copyright 2018 Dell Inc. 67 IDE Gradle – For

    what? • One more «rough» code check (e.g. imports, typos, syntax, …)
  42. © Copyright 2018 Dell Inc. 68 IDE Gradle – For

    what? • One more «rough» code check (e.g. imports, typos, syntax, …) • Jenkins dependencies
  43. © Copyright 2018 Dell Inc. 69 IDE Gradle – For

    what? • One more «rough» code check (e.g. imports, typos, syntax, …) • Jenkins dependencies • Codenarc integration
  44. © Copyright 2018 Dell Inc. 71 IDE Gradle – Jenkins

    dependencies • Custom repo • Jenkins dependencies
  45. © Copyright 2018 Dell Inc. 72 IDE Gradle – Codenarc

    integration • apply plugin: 'codenarc'
  46. © Copyright 2018 Dell Inc. 73 IDE Gradle – Codenarc

    integration • apply plugin: 'codenarc'
  47. © Copyright 2018 Dell Inc. 74 Useful things for pipelines

    developer • Groovy console in IDEA – little experiments
  48. © Copyright 2018 Dell Inc. 75 Useful things for pipelines

    developer • Groovy console in IDEA – little experiments • Jenkins Script console (carefully) – peek inside live Jenkins data structures
  49. © Copyright 2018 Dell Inc. 76 Useful things for pipelines

    developer • Groovy console in IDEA – little experiments • Jenkins Script console (carefully) – peek inside live Jenkins data structures • Don’t forget about Snippet Generator
  50. © Copyright 2018 Dell Inc. 79 Takeaways • Use static

    analysis tools: – uniform codestyle (better readability, maintainability, standard for team)
  51. © Copyright 2018 Dell Inc. 80 Takeaways • Use static

    analysis tools: – uniform codestyle (better readability, maintainability, standard for team) – detecting errors
  52. © Copyright 2018 Dell Inc. 81 Takeaways • Use static

    analysis tools: – uniform codestyle (better readability, maintainability, standard for team) – detecting errors – improve Groovy knowledge
  53. © Copyright 2018 Dell Inc. 82 Takeaways • Use static

    analysis tools: – uniform codestyle (better readability, maintainability, standard for team) – detecting errors – improve Groovy knowledge • Use IDE:
  54. © Copyright 2018 Dell Inc. 83 Takeaways • Use static

    analysis tools: – uniform codestyle (better readability, maintainability, standard for team) – detecting errors – improve Groovy knowledge • Use IDE: – autocomplete, hints, documentation and navigation for pipelines
  55. © Copyright 2018 Dell Inc. 84 Takeaways • Use static

    analysis tools: – uniform codestyle (better readability, maintainability, standard for team) – detecting errors – improve Groovy knowledge • Use IDE: – autocomplete, hints, documentation and navigation for pipelines – easy access to Jenkins source code
  56. © Copyright 2018 Dell Inc. 85 Takeaways • Use static

    analysis tools: – uniform codestyle (better readability, maintainability, standard for team) – detecting errors – improve Groovy knowledge • Use IDE: – autocomplete, hints, documentation and navigation for pipelines – easy access to Jenkins source code – everything in the one place (VCS, editor, task management, …)
  57. © Copyright 2018 Dell Inc. 86 Takeaways IDE Integration Unit

    Test Framework Static analysis Library manager Debugging tools Documentation Scripts deployment DSL migration tools
  58. © Copyright 2018 Dell Inc. 87 Takeaways IDE Integration Unit

    Test Framework Static analysis Library manager Debugging tools Documentation Scripts deployment DSL migration tools
  59. © Copyright 2018 Dell Inc. 88 Links • Codenarc –

    https://codenarc.org • Groovy style - http://groovy-lang.org/style-guide.html • GDSL - https://st-g.de/2016/08/jenkins-pipeline-autocompletion-in-intellij • GDSL and Gradle - https://intellij-support.jetbrains.com/hc/en- us/community/posts/115000140204-Setting-up-Groovy-completion-for-Jenkins-Pipelines- consumers