Su Frank
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # 透過 Docker 建立 JenkinsAgent ###### tags: `Jenkins` `Docker` ## 介紹 之前撰寫的[[透過 Docker 建立 Jenkins](/HzNLqx2TSA6885MXaDkE-A)]最後有提到,在執行各樣CI/C官方建議使用JenkinsAgent來運行,其原因主要為[安全隔離](https://www.jenkins.io/doc/book/security/controller-isolation/#not-building-on-the-built-in-node),也可以使執行不同專案的CI/CD作業時,彼此不受影響。 ## 目錄 [TOC] # 一、前言 基本上整體流程也不會太困難,這邊廢話就不多說直接進入實作 # 二、建立Jenkins 還不知道怎麼執行的可以查看此文章[透過 Docker 建立 Jenkins](/HzNLqx2TSA6885MXaDkE-A),這邊會架構在此基礎往後進行實作 # 三、新增節點 首先我們需建先建立節點,其UI操作如下 ![](https://i.imgur.com/5s0qEnp.png) 進入頁面後點選左方的**新增節點** ![](https://i.imgur.com/xGzoQ4G.png) 取個名字吧!下方選項則需要點選,然後直接點選建立 ![](https://i.imgur.com/P1PoWhd.png) 接著會針對節點進行相關設定,我們設定一個系統根目錄給它,之後捲到最下方點選儲存 ![](https://i.imgur.com/VhXGPjf.png) 完成後可以看到以下畫面,此時狀態打叉表示未連接到代理節點 ![](https://i.imgur.com/DDUmuAH.png) # 四、代理Jenkins建立 完成第二大項的步驟後,我們可以點選節點來查看相關連接資訊,進入畫面後可以看到此處有說明從Agent該如何連接,這邊的話我們只需要記住Key即可 ![](https://i.imgur.com/XmsLwcK.png) ## 運行 在運行時必須要確定master跟運行agent兩者之間的網路是否互通,此處我們透過IP來讓agent訪問master,主要指令結構如下: ```shell= docker run -d --name {CTN_NAME} --init jenkins/inbound-agent -url http://{MASTER_NODE_IP}:8080 -workDir={WORK_DIR} {KEY} {AGENT_NAME} ``` 完整指令如下: ```shell= docker run -d --name jenkins_agent --init jenkins/inbound-agent -url http://192.168.1.102:8080 -workDir=/home/jenkins/AgentNode bd38d71dc2a390f969f9e94cc7d89679eda44e3c776a26874b381810b20f2eb1 AgentNode ``` 執行後我們可以直接查看log是否連接成功 ![](https://i.imgur.com/vzaVp4L.png) 也可以進入Jenkins節點管理頁面查看連接狀況 ![](https://i.imgur.com/yMEy20u.png) 如此一來JenkinsAgent算是已經建立完成了唷! # 五、測試使用 測試前可以先閱讀[再 Jenkins 底下執行 NodeJs](/mtGREEfVTiq7mLTIPLAkfg),了解一下整體的新增/執行作業的程序如何進行,此處會快速帶過 ## 建立作業 我們建立一個Pipeline的流程,這邊增加了`agent` 並且指定對應的agent為`label 'AgentNode'`,這樣在運行的時候就會是走指定的代理,其使用腳本如下: ```json= pipeline { agent{ label 'AgentNode' } tools { nodejs '16.17.1' } stages { stage('Hello') { steps { echo 'Hello World' sh 'npm version' } } } } ``` 這邊附上畫面 ![](https://i.imgur.com/VoV5a26.png) ## 執行結果 這邊直接運行建置並且查看結果,可以看到流程是運行在我們指定的Node當中,其安裝與指令的執行也都是在此代理底下運行 ![](https://i.imgur.com/ymA1CC1.png) # 結論 經過此實作整體來說也無太大難度,比較特別的是我們在建立AgentNode的時候會有一個選項要勾起,其實也可以在運行時指定對應的DockerImage來進行相關作業操作,至於如何使用後續再來針對這一區塊做學習。 <br/> --- 相關參考來源: [Day 23: Jenkins與分散式部屬](https://ithelp.ithome.com.tw/articles/10271997) <style> .red{color: red;} </style>

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully