Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Getting started with Jenkins: Agents
Ben Selby
Ben Selby

Posted on • Edited on • Originally published atbenmatselby.dev

     

Getting started with Jenkins: Agents

Following on fromGetting started with Jenkins, this post will get a Jenkins Agent up and running your builds. Please make sure you have completed the instructions on theprevious post.

We will run the Jenkins agents in docker containers, like we have for the controller.

We need to adjust thedocker run command slightly this time around. But first, we need to define a Docker network. So let's start with creating the Jenkins network.

docker network create jenkins
Enter fullscreen modeExit fullscreen mode

The above command will define a Docker network that both our containers (controller and agent) will run in.

We want to adjust the originaldocker run command to utilise the new network. Please run the following command to get the Jenkins Controller up and running.

docker run--rm-p 8080:8080--network jenkins-v"${HOME}/.jenkins:/var/jenkins_home"--name jenkins-controller jenkins/jenkins:lts
Enter fullscreen modeExit fullscreen mode

Now we have Jenkins running, let's browse tohttp://localhost:8080, and follow the steps below:

  1. Click onManage Jenkins on the left hand side.
  2. Under theSystem Configuration section, click onManage Nodes and Clouds.
  3. On the left hand side, click onNew Node.
  4. You can name this whatever you like.
    • I'm going to call my agentsmith.
    • You will need to remember this for later.
  5. Click on thePermenant Agent radio box.
  6. ClickOK.

Now we are going to configure the agent a little more. You can play around with different settings, but to keep us on the same page, please follow the steps below for now.

  1. For theDescription field, please complete something descriptive so you know what it can be used for. Fow now, enterThis is agent smith, which is really not descriptive!
  2. Leave the number of executors to1.
    • Executors define how many Jenkins Jobs an agent can run concurrently.
    • The more CPU/Memory you give, the more concurrent jobs you can have running.
  3. Enter/home/jenkins/agent/ into theRemote root directory text field.
  4. TheLabel allows us to tie specific jobs to specific agents.
    • For example, you may have Windows, Mac, and Linux agents, that run specific software, such as iOS builds.
    • This can be used for defining those kinds of things.
    • For now, this isn't important to us, so we can leave this blank.
  5. Go ahead and clickSave.

Once you have completed the above, and clickedSave you will be presented with the agent list. As you can see,smith is listed.

Jenkins agent list

Click onsmith, so we can see the connection details.

You should be able to see some text such as this:

java-jar agent.jar-jnlpUrl http://localhost:8080/computer/smith/jenkins-agent.jnlp-secret 91af70f19b975b97eef81d42f624f1c44bl1d216b380905c9c27531d2259d823-workDir"/home/jenkins/agent/"
Enter fullscreen modeExit fullscreen mode

Copy the value from the-secret option. In this case, it is91af70f19b975b97eef81d42f624f1c44bl1d216b380905c9c27531d2259d823, but your secret will be different.

In a terminal, now run the following command, replacing

  • <secret-from-above> to your secret.
  • <agent-name-from-above> to your agent name.
docker run--rm\-eJENKINS_SECRET=<secret-from-above>\-eJENKINS_URL=http://jenkins-controller:8080\-eJENKINS_AGENT_NAME=<agent-name-from-above>\--network jenkins\--init\-it\ jenkins/inbound-agent:4.7-1
Enter fullscreen modeExit fullscreen mode

This will pull thejenkins/inbound-agent image down to your machine and then start to run it. All the different types of agent can be found onDocker Hub.

The URL may look a little odd here. TheJenkins-controller part is the name of the container running your Jenkins Controller. This is important due to us running both containers inside a network.

There should be no errors whilst running the above command, so now let's go back to Jenkins in the browser. You should now seesmith as an agent on the left hand side.

Jenkins Agent Smith connected and waiting

As you can see, we now have two build executors:master andsmith. We don't want to run any builds on the controller container (master), so let's go ahead and stop that from happening.

  1. Click onManage Jenkins on the left hand side.
  2. Under theSystem Configuration section, click onConfigure System.
  3. Scroll to# of executors and change the value from2 to0.
  4. ClickSave.

When Jenkins now loads the home page again, you will only see thesmith agent. We now want to run ourhello-world job from theprevious post, and see that it will execute inside thesmith agent.

  1. Click on thehello-world job from the list.
  2. ClickBuild Now on the left hand side.
  3. After a few moments the build job will appear in the build history.
  4. Click on the blue ball, and see the "Hello World" output again.

Jenkins Hello World running on an agent

Jenkins Hello World running on an agent with output

What's next

If you are adventurous, then the next steps would be:

  • Define your own Jenkins agent in a Dockerfile, and run that.
    • For example, get a Go or Node runtime inside it.
  • Use something likengrok to expose your installation back to GitHub, to get GitHub Events.

Summary

This was a quick overview for getting a Jenkins agent connected to the Jenkins Controller application.


See also

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Love building distributed teams, writing in Go, building CLI dev tools, engaging with other engineering teams, and learning new things
  • Location
    UK
  • Work
    Tech Lead
  • Joined

More fromBen Selby

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp