user63898
user63898

Reputation: 30885

Azure self hosted agent linux do not run with "--once" parameter

I like to run the self-hosted Linux container only once per pipeline. That means when the pipeline is done I like the container to stop. I saw that there is a parameter called "--once", see these docs: https://learn.microsoft.com/en-us/azure/devops/pipelines/agents/docker?view=azure-devops

but when I start Docker like this with the once after the run:

docker run --once --rm -it -e AZP_WORK=/home/working_dir -v /home/working_dir:/azp -e AZP_URL=https://dev.azure.com/xxxx -e AZP_TOKEN=nhxxxxxu76mlua -e AZP_AGENT_NAME=ios_dockeragent xxx.xxx.com:2000/azure_self_hosted_agent/agent:latest 

I'm getting :

unknown flag: --once
See 'docker run --help'.

also if I put it in the Dockerfile as

COPY ./start.sh .
RUN chmod +x start.sh

CMD ["./start.sh --once"]

I'm getting error when trying to run the Docker:

docker: Error response from daemon: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"./start.sh --once\": stat ./start.sh --once: no such file or directory": unknown

Where do I need to set this "--once" command in dockerized agent?

Upvotes: 0

Views: 1983

Answers (2)

Jiří Baum
Jiří Baum

Reputation: 6930

As far as I know, there's no way to pass it in from the outside; you have to go into the container and edit the start.sh file to add the --once argument to the appropriate line.

  exec ./externals/node/bin/node ./bin/AgentService.js interactive --once & wait $!
  cleanup

Side note: depending on your requirements, you might also take the opportunity to remove the undocumented web-server from start.sh.

Upvotes: 0

Shayki Abramczyk
Shayki Abramczyk

Reputation: 41545

Is for the agent's run, not the docker run. from the docs:

For agents configured to run interactively, you can choose to have the agent accept only one job. To run in this configuration:

./run.sh --once

Agents in this mode will accept only one job and then spin down gracefully (useful for running in Docker on a service like Azure Container Instances).

So, you need to add it in the bash script you configure the docker image:

FROM ubuntu:18.04

# To make it easier for build and release pipelines to run apt-get,
# configure apt to not require confirmation (assume the -y argument by default)
ENV DEBIAN_FRONTEND=noninteractive
RUN echo "APT::Get::Assume-Yes \"true\";" > /etc/apt/apt.conf.d/90assumeyes

RUN apt-get update \
&& apt-get install -y --no-install-recommends \
        ca-certificates \
        curl \
        jq \
        git \
        iputils-ping \
        libcurl4 \
        libicu60 \
        libunwind8 \
        netcat

WORKDIR /azp

COPY ./start.sh .
RUN chmod +x start.sh --once

Upvotes: 1

Related Questions