QA AND TEST AUTOMATION · PART 8 · CI/CD AND TEST INFRASTRUCTURE · CI · 75 OF 112

Jenkins for Testers: Pipelines and Reports

Jenkins from a tester's side: controllers and agents, a declarative Jenkinsfile for ShopRung's suites with stages, parallel branches, parameters, a nightly trigger, credentials and post actions that publish JUnit results and keep artifacts, plus the plugins testers use (JUnit, HTML Publisher, Allure), reading a failed build, and how Jenkins compares with GitHub Actions.

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  55. 55
  56. 56
  57. 57
  58. 58
  59. 59
  60. 60
  61. 61
  62. 67
  63. 68
  64. 69
  65. 70
  66. 71
  67. 72
  68. 73
  69. 74
  70. 75
  71. 76
  72. 77
  73. 78
  74. 79
  75. 80
  76. 81
  77. 82
  78. 83
  79. 84
  80. 85
  81. 86
  82. 87
  83. 88
  84. 89
  85. 90
  86. 91
  87. 92
  88. 93
  89. 94
  90. 95
  91. 96
  92. 97
  93. 98
  94. 99
  95. 100
  96. 101
  97. 102
  98. 103
  99. 104
  100. 105
  101. 106
  102. 107
  103. 108
  104. 109
  105. 110
  106. 111
  107. 112
1 / 12

Press play to hear the narration, or step through at your own pace.

Key takeaways

  • Controller and agents
  • Jenkinsfile
  • stages and parallel
  • credentials
  • post: junit, artifacts
  • plugins
  • triage

Notes

How it is built

Jenkins has a controller and agents. The controller is the web interface: it holds jobs, schedules runs, stores results and loads plugins. Agents are the machines or containers that actually run the steps, chosen by labels like linux or docker. Almost every feature comes from a plugin. And Jenkins is self hosted: someone in the company installs, secures and updates it, which is a big difference from hosted CI.

Jenkins parts
  • controller: web UI, jobs, schedules, plugins, results
  • agents: machines or containers that run the build steps (labels: linux, docker, gpu)
  • plugins: almost every feature (JUnit, Git, Docker, Allure)
  • self-hosted: your team runs and updates it

Pipeline as code

Modern Jenkins jobs are pipelines defined in a Jenkinsfile in the repository, reviewed like any code. The declarative style starts with pipeline. Agent says where to run, here any agent labelled linux. Options add a thirty minute timeout. Triggers add a nightly run; H spreads the exact minute so not every job starts at once. Parameters add a drop down, here the environment, shown on the build with parameters button.

Jenkinsfile (declarative)
pipeline {
  agent { label "linux" }
  options { timeout(time: 30,
    unit: "MINUTES") }
  triggers { cron("H 2 * * *") }
  parameters { choice(name: "ENV",
    choices: ["local", "staging"]) }
  stages { ... }
  post { ... }
}

Stages

Stages are the named boxes you see in the Jenkins interface. The first starts ShopRung in the background with its log saved, and waits for the health check. The tests stage has parallel branches: API and UI run at the same time on the same agent, each with its own command. Sh runs a shell command; dir changes folder. If a command exits with an error, the stage fails and turns red.

stages
stage("Start ShopRung") { steps {
  dir("shoprung") { sh """
    nohup npm start > shop.log 2>&1 &
    npx --yes wait-on@8 http-get://..."""
  } } }
stage("Tests") { parallel {
  stage("API") { steps {
    sh "cd api-tests && pytest
      --junitxml=results/api.xml" } }
  stage("UI") { steps {
    sh "cd e2e && npx playwright test" } }

Credentials

Secrets live in Jenkins' credentials store, not in the Jenkinsfile. The credentials helper in an environment block binds one to variables: for a username and password credential, you get two variables ending in U S R and P S W, and Jenkins masks them in the console log. Tests read them as environment variables. Never print them, and never write them into reports.

Using a secret
environment {
  ALICE = credentials("shoprung-alice")
}
// a "username with password"
// credential gives:
//   ALICE_USR and ALICE_PSW
// Jenkins masks them in the log

never: echo $ALICE_PSW

Post actions

Post actions run after the stages. Always runs whatever happened: the junit step reads every JUnit XML file and shows a test results page with trends across builds; archive artifacts keeps ShopRung's log and Playwright's test results with the build. Failure runs only when the build failed, a good place to notify the team. The junit step also marks the build unstable, shown yellow, when tests failed but the commands themselves ran.

post
post {
  always {
    junit "**/results/*.xml"
    archiveArtifacts artifacts:
      "shoprung/shop.log, **/test-
       results/**", allowEmptyArchive:
       true
  }
  failure { echo "notify the team" }
}

Plugins for testers

Plugins testers use most: JUnit, for results, trends and the history of each test. HTML publisher, to show the Playwright report inside Jenkins. Allure, for an Allure report per build with history. A pipeline graph view for a visual picture of stages. And Docker pipeline, so a stage can run inside a container image with the right browsers installed, which keeps agents simple.

Useful plugins
  • JUnit: test results, trends, history of each test
  • HTML Publisher: show the Playwright HTML report
  • Allure: Allure report per build with history
  • Pipeline Graph View / Blue Ocean: visual stages
  • Docker Pipeline: agent { docker }

Reading a failed build

When a build is red, look in this order. The stage view shows which stage failed. The test result page lists failing tests with errors and stack traces, and each test's history shows since which build it fails, which often points straight at a commit. Then artifacts: the app log, traces and screenshots. The raw console output is the last resort. The changes page lists the commits in the build.

Triage order
  • 1 stage view: which stage went red?
  • 2 Test Result: which tests, error, stack trace, history (failing since build #?)
  • 3 artifacts: app log, traces, screenshots
  • 4 console output: last resort
  • 5 Changes: which commits

Versus GitHub Actions

Compared with GitHub Actions: Jenkins is self hosted, with a huge choice of plugins, can reach internal company systems easily, and uses Groovy based pipelines, but it needs care and updates. GitHub Actions is hosted next to the code, uses YAML and a marketplace of actions, and needs little upkeep. The concepts carry over directly: stages or jobs, parallel runs, secrets, artifacts and test reports.

Compared
  • Jenkins: self-hosted, huge plugin choice, any network (internal systems), Groovy pipelines; needs upkeep
  • GitHub Actions: hosted with the code, YAML, marketplace, little upkeep
  • same concepts: stages/jobs, parallel, secrets, artifacts

Common mistakes

Jenkins mistakes. Jobs configured only by clicking in the UI, so nobody can review or restore them. Secrets echoed into the log. No junit step, so results exist only in console text. No timeout. Long lived agents full of old browsers and leftover processes, so builds behave differently on each machine; containers fix that. And running builds on the controller itself, which is slow and insecure.

Avoid these
  • jobs configured only in the UI (not in Git)
  • secrets echoed in the log
  • no junit step: results only in the console
  • no timeout on the pipeline
  • agents full of old browsers and leftover processes
  • everything on the controller

Say it like this

In the interview: a declarative Jenkinsfile in the repository. One stage starts the app and waits for its health check; API and UI tests run as parallel stages inside a Docker agent with the right browsers. Credentials come from the credentials store, and post always publishes JUnit results and the HTML report and archives logs and traces. A nightly cron trigger, a parameter for the environment, and timeouts on everything.

In the interview
  • "Declarative Jenkinsfile in the repo: a stage starts the app and waits on health, API and UI run
  • as parallel stages in a Docker
  • agent, credentials via credentials(), and post always
  • publishes JUnit, the HTML report
  • and archives logs and traces.
  • Nightly cron, parameters for environment, timeouts."

Interview questions

Q1What is a Jenkinsfile?

A file in the repository that defines a Jenkins pipeline as code, usually in declarative syntax: agent, options, triggers, parameters, stages and post.

Q2What is the difference between the Jenkins controller and agents?

The controller hosts the UI, jobs, scheduling and results; agents are machines or containers that execute pipeline steps.

Q3How do you run test suites in parallel in Jenkins?

Use a parallel block inside a stage, with one nested stage per suite, or separate agents per branch.

Q4How do you publish test results in Jenkins?

The junit step in post { always { ... } } reads JUnit XML; HTML Publisher or Allure plugins show richer reports; archiveArtifacts keeps evidence.

Q5How are secrets handled in Jenkins pipelines?

Stored in the credentials store and bound with credentials() or withCredentials; values are masked in logs.

Q6What does an "unstable" (yellow) build mean?

The steps ran but tests reported failures (set by the junit step), unlike a failed (red) build where a step itself failed.

Q7How do you schedule a nightly run?

triggers { cron("H 2 * * *") } in the Jenkinsfile; H spreads the start minute.

Q8Jenkins or GitHub Actions?

Jenkins: self-hosted, plugins, internal networks, more upkeep. GitHub Actions: hosted with the code, YAML, less upkeep. The pipeline concepts are the same.