what is the difference between "withRun" and "inside" in Jenkinsfile? what is the difference between "withRun" and "inside" in Jenkinsfile? docker docker

what is the difference between "withRun" and "inside" in Jenkinsfile?


Image.run([args, command])
Uses docker run to run the image, and returns a Container which you could stop later. Additional args may be added, such as '-p 8080:8080 --memory-swap=-1'. Optional command is equivalent to Docker command specified after the image. Records a run fingerprint in the build.

Image.withRun[(args[, command])] {…}
Like run but stops the container as soon as its body exits, so you do not need a try-finally block.

Image.inside[(args)] {…}
Like withRun this starts a container for the duration of the body, but all external commands (sh) launched by the body run inside the container rather than on the host. These commands run in the same working directory (normally a Jenkins agent workspace), which means that the Docker server must be on localhost.

So as you can tell from the above, your sh method commands (specifically the npm commands) will execute on the host for withRun, but within the container for inside.

Link to the docs: https://opensource.triology.de/jenkins/pipeline-syntax/globals