使用指令行用戶端建立元件

如果 IBM® UrbanCode Deploy 沒有建置系統的來源配置類型,則可以使用 udclient 指令行用戶端來管理元件。

開始之前

若要安裝用戶端,請參閱Installing the command-line client

關於這項作業

當您以此方法使用 udclient 用戶端時,可以將新版本的元件推送至伺服器,啟動程序,新增指向外部來源的鏈結,以及作為建置程序的一部分在 IBM UrbanCode Deploy 伺服器上執行許多其他作業。透過這種方式,您可以在 IBM UrbanCode Deploy 中處理元件,而無需變更建置技術。

程序

遵循下列一般步驟,以設定使用指令行用戶端的元件:

  1. IBM UrbanCode Deploy 中建立一個以上元件,以代表建置的元件。請使用「建立新的元件」視窗中的下列參數:
    • 來源配置類型欄位中,選取
    • 清除自動匯入版本勾選框。
    • 正常完成視窗中的剩餘欄位。
  2. 在元件的建置 Script 中,新增呼叫 udclient 用戶端指令的程式碼,以建立元件版本,並將構件上傳至 IBM UrbanCode Deploy 伺服器。 在大部分情況下,您使用數個不同的指令來建立版本。下列步驟顯示了您可能使用的部分指令的範例。
    註: 這些範例使用 Apache Ant 建置檔中的程式碼。具體而言,它們使用 Ant <exec> 指令呼叫 udclient 用戶端,該用戶端會呼叫外部程式。如果是使用不同的建置技術,則必須改寫建置技術的範例,以呼叫 udclient 用戶端。
    1. 使用 createVersion 指令,以建立新版本。 下列程式碼範例建立名為 mycomponent 的元件版本。版本名稱已設為建置的時間戳記。變數 ${udclient.weburl}${udclient.username}${udclient.password} 分別代表伺服器的 URL 以及伺服器的使用者名稱與密碼。
      <exec executable="/bin/bash" 
        outputproperty="mycomponent.component.output">
      
        <arg value="/opt/udclient/udclient"/>
      
        <arg value="-weburl"/>
        <arg value="${udclient.weburl}"/>
      
        <arg value="-username"/>
        <arg value="${udclient.username}"/>
      
        <arg value="-password"/>
        <arg value="${udclient.password}"/>
      
        <arg value="createVersion"/>
      
        <arg value="-component"/>
        <arg value="mycomponent"/>
      
        <arg value="-name"/>
        <arg value="${buildTimestamp}"/>
      
      </exec>
    2. 使用 addVersionFiles 指令,以將構件上傳至元件版本。 下列程式碼範例將 ${destdir} 資料夾中的檔案上傳至版本:
      <exec executable="/bin/bash">
      
        <arg value="/opt/udclient/udclient"/>
        
        <arg value="-weburl"/>
        <arg value="${udclient.weburl}"/>
        
        <arg value="-username"/>
        <arg value="${udclient.username}"/>
        
        <arg value="-password"/>
        <arg value="${udclient.password}"/>
        
        <arg value="addVersionFiles"/>
        
        <arg value="-component"/>
        <arg value="mycomponent"/>
        
        <arg value="-version"/>
        <arg value="${buildTimestamp}"/>
        
        <arg value="-base"/>
        <arg value="${destdir}"/>
        
      </exec>
    3. 選擇性的: 從元件版本新增鏈結。 使用 addVersionLink 指令,您可以新增從版本至外部建置資源(例如顯示建置結果相關資訊的頁面)的鏈結。這些鏈結出現在元件版本資訊頁面的頂端。下圖顯示含指向原始碼管理系統中相關建置工具及相關建置結果鏈結的元件版本:
      鏈結區段中含兩個鏈結的元件版本
      例如,下列程式碼新增建置結果頁面(URL 為 http://build.example.com/projects/mycomponent/${buildResultUUID})的鏈結:
      <exec executable="/bin/bash">
      
        <arg value="/opt/udclient/udclient"/>
        
        <arg value="-weburl"/>
        <arg value="${udclient.weburl}"/>
        
        <arg value="-username"/>
        <arg value="${udclient.username}"/>
        
        <arg value="-password"/>
        <arg value="${udclient.password}"/>
        
        <arg value="addVersionLink"/>
        
        <arg value="-component"/>
        <arg value="mycomponent"/>
        
        <arg value="-version"/>
        <arg value="${buildTimestamp}"/>
        
        <arg value="-linkName"/>
        <arg value="External build result"/>
        
        <arg value="-link"/>
        <arg value="http://build.example.com/projects/mycomponent/${buildResultUUID}"/>
        
      </exec>

結果

現在,當您在外部建置工具中執行建置時,建置程序會建立一個元件版本,並將版本構件上傳至 IBM UrbanCode Deploy 伺服器。以此來說,您可以正常使用伺服器上的元件及版本,例如對其執行程序。

您也可以將其他指令新增至建置 Script。例如,您可以使用 requestApplicationProcess 指令來啟動應用程式程序。


意見