0

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"
please this link in the bottom :
https://learn.microsoft.com/en-us/azure/devops/pipelines/agents/docker?view=azure-devops

but when i start the 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 docker file as

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

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

Im 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?

user63898
  • 29,839
  • 85
  • 272
  • 514

2 Answers2

1

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
Shayki Abramczyk
  • 36,824
  • 16
  • 89
  • 114
0

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.

Jiří Baum
  • 6,697
  • 2
  • 17
  • 17
  • Thank , but i dont understand this is not what written in the documents why i need to remove the web server ? also why i need to add the & wait $!? – user63898 Sep 16 '20 at 04:51
  • Web server — that's up to you. If you need it, keep it; if you don't want it, remove it. It's entirely undocumented and doesn't appear to serve any useful purpose. Certainly the agent works fine without it. – Jiří Baum Sep 16 '20 at 05:44
  • The `& wait $!` is so the `cleanup` function can be run after the agent exits. If I remember correctly, this de-registers the agent from the pool. Probably it could be omitted if the `exec` is also removed. – Jiří Baum Sep 16 '20 at 05:46
  • 1
    wander why it is not documented – user63898 Sep 16 '20 at 06:24
  • My guess is that the webserver is a dummy health-check endpoint; always returns a 3xx redirect response, without regard to agent health. It could also for some "must have a web interface" requirement checkbox; it redirects to the admin interface on Azure, rather than just giving "200 OK". – Jiří Baum Sep 17 '20 at 02:34