Answers: <p>You could use the <a href="https://wiki.jenkins.io/display/JENKINS/Amazon+EC2+Plugin" rel="nofollow noreferrer">EC2 plugin</a> or the <a href="https://wiki.jenkins.io/display/JENKINS/Amazon+EC2+Container+Service+Plugin" rel="nofollow noreferrer">ECS plugin</a> if you want to provision agents dynamically. These would provide some environment variables to use when constructing <code>build_id</code> - <em>e.g.</em> :</p>
  
  <ul>
  <li><code>BUILD_TAG</code>: 
  
  <blockquote>
    <p>String of "jenkins-${JOB_NAME}-${BUILD_NUMBER}". All forward slashes ("/") in the JOB_NAME are replaced with dashes ("-"). Convenient to put into a resource file, a jar file, etc for easier identification.</p>
  </blockquote></li>
  <li><code>NODE_NAME</code>:
  
  <blockquote>
    <p>Name of the agent if the build is on an agent, or "master" if run on master</p>
  </blockquote></li>
  </ul>
  
  <p>You would have to configure the clouds in Jenkins, assign a label to the templates you want to use as agents, and then request those in your pipeline or job configuration.</p>
  
Answers: CC BY-SA 4.0
Answers: 2019-12-26T17:47:31.280Z
Answers: Does slave jenkins cluster register with ECS service? because master jenkins cluster register with ECS service
Answers: overexchange
Answers: CC BY-SA 4.0
Answers: 2019-11-04T16:11:37.840Z
Answers: 2019-11-04T16:11:37.840Z
Answers: Bruce Becker
Body: <p>Below code snippet, taken from <a href="https://github.com/jmenga/docker-jenkins/blob/master/Dockerfile#L16" rel="nofollow noreferrer">here</a> creates master jenkins that runs in a container:</p>
  
  <pre><code># Create Docker Group with GID
  # Set default value of 497 if DOCKER_GID set to blank string by Docker Compose
  RUN groupadd -g ${DOCKER_GID:-497} docker
  
  # Used to control Docker and Docker Compose versions installed
  # NOTE: As of February 2016, AWS Linux ECS only supports Docker 1.9.1
  ARG DOCKER_ENGINE=1.10.2
  ARG DOCKER_COMPOSE=1.6.2
  
  # ......
  
  # Install Docker Engine
  RUN apt-key adv --keyserver hkp://pgp.mit.edu:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D &amp;&amp; \
      echo "deb https://apt.dockerproject.org/repo ubuntu-trusty main" | tee /etc/apt/sources.list.d/docker.list &amp;&amp; \
      apt-get update -y &amp;&amp; \
      apt-get purge lxc-docker* -y &amp;&amp; \
      apt-get install docker-engine=${DOCKER_ENGINE:-1.10.2}-0~trusty -y &amp;&amp; \
      usermod -aG docker jenkins &amp;&amp; \
      usermod -aG users jenkins
  </code></pre>
  
  <hr>
  
  <p>Above container is dind that launches task(each container) on <strong>single</strong> EC2 host.</p>
  
  <hr>
  
  <p>To regulate load across <strong>multiple</strong> EC2 host and launch slave jenkins instance(on each).</p>
  
  <p>We would like to have <code>master</code> jenkins generate <code>build_id</code> for each build that can run on two slave jenkins instances.</p>
  
  <p>To have master &amp; slave jenkins run within each container, across EC2 hosts.</p>
  
  <p>How to approach on making slave container and take <code>build_id</code> from master jenkins?</p>
  
Comments: CC BY-SA 4.0
Comments: 2019-11-04T15:54:11.653Z
Comments: Hi there - perhaps it's just me, but I'm having a really hard time understanding what you want to do, reading this this post. The Dockerfile you provided doesn't seem to start anything, just does docker-in-docker.  Do you want to have a multi-master jenkins setup? Do you want multi-cluster agents spawns? Help us understand what you're trying to do please :)
Comments: Bruce Becker
Comments: CC BY-SA 4.0
Comments: 2019-11-04T15:55:29.460Z
Comments: @BruceBecker a single master Jenkins that has two slave Jenkins. Each jenkins(master and slave)  run on their own  ECS cluster instance
Comments: overexchange
Comments: CC BY-SA 4.0
Comments: 2019-11-04T15:59:22.370Z
Comments: Thanks! that clarifies things a lot.
Comments: Bruce Becker
Tags: <docker><jenkins><docker-compose><dockerfile>
Title: How to create slave jenkins given master jenkins?
UserDisplayName: overexchange
ThreadText: # How to create slave jenkins given master jenkins?
  
  (Asked by: username_0 on 2019-11-04)
  
  Below code snippet, taken from [here](https://github.com/jmenga/docker-jenkins/blob/master/Dockerfile#L16) creates master jenkins that runs in a container:
  
  ```
  # Create Docker Group with GID
  # Set default value of 497 if DOCKER_GID set to blank string by Docker Compose
  RUN groupadd -g ${DOCKER_GID:-497} docker
  
  # Used to control Docker and Docker Compose versions installed
  # NOTE: As of February 2016, AWS Linux ECS only supports Docker 1.9.1
  ARG DOCKER_ENGINE=1.10.2
  ARG DOCKER_COMPOSE=1.6.2
  
  # ......
  
  # Install Docker Engine
  RUN apt-key adv --keyserver hkp://pgp.mit.edu:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D && \
      echo "deb https://apt.dockerproject.org/repo ubuntu-trusty main" | tee /etc/apt/sources.list.d/docker.list && \
      apt-get update -y && \
      apt-get purge lxc-docker* -y && \
      apt-get install docker-engine=${DOCKER_ENGINE:-1.10.2}-0~trusty -y && \
      usermod -aG docker jenkins && \
      usermod -aG users jenkins
  
  ```
  
  ---
  
  Above container is dind that launches task(each container) on **single** EC2 host.
  
  ---
  
  To regulate load across **multiple** EC2 host and launch slave jenkins instance(on each).
  
  We would like to have `master` jenkins generate `build_id` for each build that can run on two slave jenkins instances.
  
  To have master & slave jenkins run within each container, across EC2 hosts.
  
  How to approach on making slave container and take `build_id` from master jenkins?
  
  **Tags:** docker, jenkins, docker-compose, dockerfile
  
  > **Comments:**
  > **username_1**: Hi there - perhaps it's just me, but I'm having a really hard time understanding what you want to do, reading this this post. The Dockerfile you provided doesn't seem to start anything, just does docker-in-docker.  Do you want to have a multi-master jenkins setup? Do you want multi-cluster agents spawns? Help us understand what you're trying to do please :)  
  > **username_0**: @username_1 a single master Jenkins that has two slave Jenkins. Each jenkins(master and slave)  run on their own  ECS cluster instance  
  > **username_1**: Thanks! that clarifies things a lot.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-11-04. Score: 2 | Accepted answer
  
  You could use the [EC2 plugin](https://wiki.jenkins.io/display/JENKINS/Amazon+EC2+Plugin) or the [ECS plugin](https://wiki.jenkins.io/display/JENKINS/Amazon+EC2+Container+Service+Plugin) if you want to provision agents dynamically. These would provide some environment variables to use when constructing `build_id` - *e.g.* :
  
  * `BUILD_TAG`:
    > String of "jenkins-${JOB\_NAME}-${BUILD\_NUMBER}". All forward slashes ("/") in the JOB\_NAME are replaced with dashes ("-"). Convenient to put into a resource file, a jar file, etc for easier identification.
  * `NODE_NAME`:
    > Name of the agent if the build is on an agent, or "master" if run on master
  
  You would have to configure the clouds in Jenkins, assign a label to the templates you want to use as agents, and then request those in your pipeline or job configuration.
  
  > **Comments:**
  > **username_0**: Does slave jenkins cluster register with ECS service? because master jenkins cluster register with ECS service  
  
  ---
  
  