# Jenkins sh command is stuck

**URL:** <https://community.jenkins.io/t/jenkins-sh-command-is-stuck/35704>\
**Category:** Ask a question\
**Created:** [October 12, 2025, 6:11am UTC](https://community.jenkins.io/t/jenkins-sh-command-is-stuck/35704 "2025-10-12T06:11:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![psquared-dev](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/psquared-dev/32/17519_2.png) [@psquared-dev](https://community.jenkins.io/u/psquared-dev)\
**Post date:** [October 12, 2025, 6:11am UTC](https://community.jenkins.io/t/jenkins-sh-command-is-stuck/35704/1 "2025-10-12T06:11:54Z")

</div>

Hi

sh command inside the Jenkinsfile is stuck. Here is the content:

```Jenkinsfile
pipeline {
    agent {
        docker {
            image 'my-maven-aws-cli'
            args "-u jenkins"
        }
    }
    
    stages {
        stage('Build') {
            steps {
                echo "hi"
                sh 'id'
            }
        }
    }
}

```

I created this `my-maven-aws-cli` image using the following `Dockerfile`:

```Dockerfile
# Base Maven image
FROM maven:3.9.9-eclipse-temurin-21

USER root

# Create a jenkins user and group
ARG USER_ID=1001
ARG GROUP_ID=1001

RUN groupadd -g $GROUP_ID jenkins \
    && useradd -m -u $USER_ID -g jenkins jenkins

# Install dependencies for AWS CLI
RUN apt-get update && \
    apt-get install -y unzip curl ca-certificates && \
    rm -rf /var/lib/apt/lists/*

# Install AWS CLI v2
RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "/tmp/awscliv2.zip" && \
    unzip /tmp/awscliv2.zip -d /tmp && \
    /tmp/aws/install && \
    rm -rf /tmp/awscliv2.zip /tmp/aws

# Install Docker CLI using your commands
RUN mkdir -p /etc/apt/keyrings && \
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc && \
    chmod a+r /etc/apt/keyrings/docker.asc && \
    echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null && \
    apt-get update && \
    apt-get install -y docker-ce-cli && \
    rm -rf /var/lib/apt/lists/*

```

If I change `args` to `args "-u root"`, then it starts working. Why it is not executing with `jenkins` user.

Thanks

---

<div class="post-metadata">

**Author:** ![MarkEWaite](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/markewaite/32/20_2.png) [@MarkEWaite](https://community.jenkins.io/u/MarkEWaite)\
**Post date:** [October 12, 2025, 10:42pm UTC](https://community.jenkins.io/t/jenkins-sh-command-is-stuck/35704/2 "2025-10-12T22:42:54Z")

</div>

> [@psquared-dev](#):
>
> `USER root`

I think that you need `USER jenkins` as the last statement in the Dockerfile. A [Docker blog post](https://www.docker.com/blog/understanding-the-docker-user-instruction/) says:

> The [`USER` instruction](https://docs.docker.com/reference/dockerfile/) in a Dockerfile is a fundamental tool that determines which user will execute commands both during the image build process and when running the container.

Since you never declared that the container should run as the `USER jenkins`, it runs as the `USER root`.

---

<div class="post-metadata">

**Author:** ![psquared-dev](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/psquared-dev/32/17519_2.png) [@psquared-dev](https://community.jenkins.io/u/psquared-dev)\
**Post date:** [October 15, 2025, 6:44am UTC](https://community.jenkins.io/t/jenkins-sh-command-is-stuck/35704/3 "2025-10-15T06:44:25Z")

</div>

Thank you so much. I was stuck on it for 2 days.
