I have created a pipeline in Jenkins whose steps are:
- git pull(retrieve the app from GitHub)
- build (maven package the app)
- building an image
- running an image
code for running the image is
docker run -d --name **application_name** -p 8081:8081 **application_name**
I need an if-else condition to check if the image has been created or not. for eg.
if (image not created)
create the image
else
different step
I need this because every time I change something in code, Jenkins throws an error stating that the image is already running.
The error might be related to this question.
You could just build the image anyway, since it wouldn't matter much if it was build again.
It you want to check if the image already exists you could use the docker images command and check if the image exists like described here.
It could look something like this: