Cài đặt jenkins on windows

The procedures in this chapter are for new installations of Jenkins.

Jenkins is typically run as a standalone application in its own process with the built-in Java servlet container/application server (Jetty).

Jenkins can also be run as a servlet in different Java servlet containers such as Apache Tomcat or GlassFish. However, instructions for setting up these types of installations are beyond the scope of this chapter.

Please submit your feedback about this page through this quick form.

Alternatively, if you don't wish to complete the quick form, you can simply indicate if you found this page helpful?

See existing feedback here.

Bạn cần có setup sẵn 1 máy Windows với OpenJDK hoặc có hỗ trợ Java.

Cài OpenJDK

  • Tải file zip cài đặt cho Windows OpenJDK 17
  • Unzip nội dung file C:Users[your username]jdk
  • Từ start menu của Windows, nhập “env” để hiển thị mục “Edit the system environment variables” sau đó chọn mở menu.
  • Chọn “Environment Variables”.
  • Dưới mục System Variables, click vào New… sau đó thêm vào JAVA_HOME cho phần Variable name và đường dẫn đến JDK.
  • Click OK và đóng cửa sổ Environment Variables.
  • Mở command line kiểm tra Java cài đặt thành công. %JAVA_HOME%\bin\java --version

Cài đặt jenkins on windows

Tạo Node trên Jenkins

  • Đăng nhập vào Jenkins với quyền Admin.
  • Vào mục Manage Jenkins.
  • Chọn Manage Nodes and Clouds.

Download Jenkins Slave và cài đặt

  • Tải bản mới nhất Jenkins Windows Service tại https://repo.jenkins-ci.org/ui/native/releases/com/sun/winsw/winsw/
  • Đặt tên file chạy jenkins-slave.exe vào thư mục C:\jenkins
  • Tạo file jenkins-slave.xml như bên dưới cùng thư mục jenkins-slave.exe.

Chi tiết cấu hình file bạn có thể tham khảo tại đây

<service>
  <id>JenkinsSlave</id>
  <name>Jenkins agent</name>
  <description>This service runs an agent for Jenkins automation server.</description>
  <executable>%JAVA_HOME%\bin\java.exe</executable>
  <arguments>-Xrs -jar &quot;%BASE%\slave.jar&quot; -jnlpUrl https://[yourjenkins.com]/computer/yournode/jenkins-agent.jnlp -secret 12asddg3s412asddg3s412asddg3s412asddg3s4buhie74 -workDir "C:\jenkins"</arguments>
  <logmode>rotate</logmode>
  <onfailure action="restart">
    <download from="https://[yourjenkins.com]/jnlpJars/slave.jar" to="%BASE%\slave.jar">
      <extensions>
        <extension className="winsw.Plugins.RunawayProcessKiller.RunawayProcessKillerExtension" enabled="true" id="killOnStartup">
          <pidfile>%BASE%\jenkins_agent.pid</pidfile>
          <stopTimeout>5000</stopTimeout>
          <stopParentFirst>false</stopParentFirst>
        </extension>
      </extensions>
    </download>
  </onfailure>
</service>

Chạy lệnh jenkins-slave.exe installđể cài đặt Jenkins slave dưới dạng Windows Service.

Khi cài đặt thành công, bạn sẽ nhận được message “Installing the service with id ‘JenkinsSlave’…”.

Bạn có thể kiểm tra service bằng cách vào me menu Windows StartRun rồi gõ services.msc

Cài đặt jenkins on windows

Lỗi hay gặp

Agent chưa được mở inbound cho phép slave kế nối Jenkins master. Message lỗi sẽ có đoạn java.lang.Exception: The server rejected the connection: None of the protocols are enabled

Bạn kiểm tra xem Jenkins đã được bật cấu hình cho phép kế slave nối. Hãy vào Jenkins -> Global Security Configuration -> Agents -> Agent protocols -> Inbound TCP Agent Protocol/4 (TLS encryption). Save và thử kiế start slave lại nhé.

Cài đặt jenkins on windows