It is important to note that the Unix commands in the pipeline script, date and time are executed using the 'sh' step and enclosed within "triple double quotes," enabling string interpolation and the accommodation of multiline strings.

From the build console output, it's quite obvious that the command has been executed, and as per line 8, in the trimmed output above, date and time output is shown on the standard out.

Code Execution Demystified

In Jenkins v2.x, it is possible that the pipeline builds can survive interruptions to the Jenkins service. So, how does Jenkins handles this code execution?

With a little bit of instrumentation, by adding the sleep command, the longevity of the code execution allows us to examine and understand what's happening here.

With the SSH access to the build agent, test-agent , I check the process table in the agent. From the trimmed output (of the process table), we find a set of processes running as generic user, build .

It's time for some in-depth analysis.

Build Workspace

From the process output, it can be inferred that the build workspace is, '/Users/jenkins/workspace/testbuild-result'; however, there are several other interesting things that are worth further discussion.

Parent and Child Processes

It is interesting to observe how the three lines of code are handled here.

The main Java process, 14355, has kicked off the execution of the code, via 5356; let's call this the main process. This "main" has spawned off another one, 5359, which owns the "script.sh" and this has created a child process, 5360, to execute the sleep command. This chain of processes isn't anything unusual but Jenkins ensures this is recorded as the process id of the "main" process, 5356.

Build Durability

At the global level, depending on the needs of the organization or the hosted projects, the durability setting can be configured globally in Jenkins. Check out Jenkins doc on pipeline durability.

Within <workspace@tmp>, durable folder is created and suffixed with a unique 8-digit ID.

What's Inside the "tmp"?

Code that was within the "sh" step is munged as script.sh and this script finds storage in a temporary directory, named, "testbuild-result@tmp" — ephemeral in nature. Within this temporary folder, there are few files, named "pid," "script.sh," and "jenkins-log.txt."