【问题标题】:Jenkins docker pipeline not passing exit codesJenkins docker pipeline not passing exit codes
【发布时间】:2022-12-02 01:45:43
【问题描述】:

we had some issues with jenkins docker stages, where they needed to be run with root permissions (args root:root). At this time, I'm not 100% recalling why they made this decision, but I couldn't get around it a few months ago.

The issue we mainly ran into with root:root was that jenkins couldn't clean up after itself, as the docker filesystem was owned by root user.

So, I created created some mascarade commands in my global groovy library

def container_init (myUserId) {
    sh( returnStdout: true, script: """/usr/sbin/useradd -u ${myUserId} dummy;""").trim()
}
def command (input) {
    sh( returnStdout: true, script: """su dummy -c '${input}';""").trim()
}

The problem now is that some of these docker_mask.command() are not passing exit code from failed e2e tests or even failed terraform deployments. Some are passing and positively exciting, but it's inconsistent.

Anything I can do to get positive exits?

【问题讨论】:

    标签: docker jenkins


    【解决方案1】:

    It seems like the issue you are facing is related to the use of the root:root arguments in your Jenkins pipeline. Using root:root as the user and group for the Docker container can cause problems, such as the one you mentioned where Jenkins is unable to clean up after itself because the Docker filesystem is owned by the root user.

    One solution to this problem is to avoid using root:root as the user and group for your Docker container, and instead use a user and group that Jenkins has permissions to access and modify. This will allow Jenkins to clean up after itself and avoid issues with exit codes.

    Another potential solution is to use the jenkins user and group for the Docker container. This will allow Jenkins to run the Docker container with the necessary permissions, while still allowing it to clean up after itself.

    Finally, you may want to consider using the docker.withRegistry method in your pipeline, which allows you to specify a registry and credentials for pulling and pushing Docker images. This can help you avoid issues with permissions and exit codes when using Docker in your Jenkins pipeline.

    【讨论】:

    • Clean-up isn't the issue; the issue is the exit codes.
    猜你喜欢
    • 2017-09-17
    • 1970-01-01
    • 2020-10-18
    • 2019-03-04
    • 1970-01-01
    • 2018-08-10
    • 2018-06-19
    • 2019-06-26
    • 2020-09-10
    相关资源
    最近更新 更多