How to resolve “Cannot retrieve .Id from docker” when building Docker image using Jenkins pipeline

前端 未结 4 397
南笙
南笙 2020-12-29 22:31

I am using a Jenkins pipeline to build a Dockerfile.

The dockerfile successfully goes through all steps, and creates the docker image.

As shown:

<         


        
4条回答
  •  太阳男子
    2020-12-29 23:16

    None of the above ideas works for my case, and I finally got it work as below pipeline without chaning anything on Dockerfile:

    1. Hardcode the build tag like "latest",
    2. Get your own tag via sh,
    3. Push your image with the hardcoded tag first,
    4. Push the image again with your customized tag.
    def my_own_tag = "unknown"
    my_own_tag = sh ( script: 'git tag | tail -n1', returnStdout: true ).trim()
    docker_img = docker.build("latest")
    docker_img.push("latest")
    docker_img.push("${my_own_tag}")
    

提交回复
热议问题