0

I have an Image A, which has a python file "main.py". I want to know how I can use Jenkins to run that file from a different pipeline. I want to use Jenkins to go inside that image and then run that file which is inside Image A.

I tried using .withRun but I don't think I'm doing this right.

docker.image(ImageA).withRun() {
    sh "main.py ${parameters to pass}"
}

When I run it like this, it executes the local main.py that I have and executes that inside the container which isn't what I want. I want to execute the main.py that is already inside the container and pass in parameters.

Any ideas?

2
  • You can use the inside command (see more info) which will execute your shell command inside the docker image using the local image files as you want. Something like: docker.image(ImageA).inside() {...} Commented Nov 14, 2021 at 22:57
  • @NoamHelmer when I use the .inside() and I use a sh command and pass in my main.py, it's looking for main.py from within the current build and not within Image B. I heard a better way to do this would be to somehow use build artifacts to access files from another workspace (imageB). Commented Nov 15, 2021 at 18:15

1 Answer 1

0

I actually figured out the solution. In the ImageA pipeline, I added the 'main.py' to the artifacts and then in ImageA, I cloned 'main.py' and executed it.

ImageA:

always {
        archiveArtifacts artifacts: 'main.py', onlyIfSuccessful: true
    }

Current pipeline:

sh "curl {url to imageA artifact}/main.py -o main.py"
docker.image(ImageA).inside {

    sh "python main.py "

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.