Alexander
I didn't quite understand the problem with you actual code. If it's about failing in the middle of pipe series, then just write set +o pipefail
at the beginning of script.
I am sorry. actually, I try to use gitlab ci runner to build the docker image. Before the build script, I need kill the last build. I try to use 'grep' to serch the image id and the port to find the actual container id, so that i can use docker kill container id to kill. When i commit the change, gitlab ci dosen't work.
So i try to find the reson why the job faild. I add 'echo $IMAGE_ID' and 'docker ps | grep $IMAGE_ID'. the "echo $IMAGE_ID" worked, show the current variable. "docker ps | grep $IMAGE_ID" was failed. so I am wonder maybe the reason is the return code 1.
Then i add "id=docker ps | grep $IMAGE_ID" to test. failed again.
So i guess the reson is 'grep' cant get the variable $IMAGE_ID, but i dont why and how to fix?
Could you understand? I appreciate your willingness to help me.🥺