2012-11-16 33 views
10

In Jenkins "Publish over Ssh"插件如何使用Label(高級選項)aka參數化發佈功能。我如何使用標籤字段。我在「標籤」字段中輸入什麼內容?我是否需要放置一個變量名稱(我可以從構建參數中讀取),該名稱將具有計算機名稱。我嘗試了相同的 這裏是我所做的:如何使用通過SSH插件的標籤字段發佈來控制Jenkins中的參數化發佈

我有一臺機器名稱QA_1,我有一個變量jenkins生成$ MC_NAME指向XXX。我在LABEL字段中輸入了$ MC_NAME。但令我驚訝的是,Jenkins正在將其發佈到QA_1機器,而不考慮$ MC_NAME變量的價值。

能有一個人請告訴我具體步驟來控制通過使用標籤,申請發佈/運行腳本,該機在詹金斯「發佈通過SSH」插件

回答

7

您應該啓用「參數化的出版」,並指定通過單擊構建配置中的「添加構建後行爲」按鈕(例如,使用構建後行爲部分)前的最後一個「高級...」按鈕來構建參數名稱。

E.g. 「建立參數名稱」= SSH_SERVER。然後應該有SSH_SERVER構建參數與regexp匹配的SSH服務器標籤。

在你的情況下,SSH_SERVER的構建參數應該設置爲XXX,之後,SSH發佈應該只發生在QA_1服務器上。

+0

啊,只是錯過了高級按鈕存在以下添加傳送設置按鈕,感謝您的幫助 – RamNat

+0

很多傢伙這也適用於發佈了FTP(也可能是其他任何插件的發佈結束了...家庭「),我花了一段時間才弄清楚爲什麼通過FTP發佈忽略了我的標籤。文檔:https://wiki.jenkins-ci.org/display/JENKINS/Publish+Over#PublishOver-Parametername – AlexMA

+0

任何人都可以解釋「標籤」字段的含義是什麼呢? –

10
Answer on your question and how I configured my process: 

**1. Configuring Jenkins** 
1.1 Install Publish over Ssh plugin 
1.2 Configure Jenkins => System Configuration 
1.2.1 Publish over SSH section 
1.2.1.1 Key => -----BEGIN RSA PRIVATE KEY----- ... here is your key ... -----END RSA PRIVATE KEY----- 
1.2.1.2 SSH Servers => 
    * Name => Server_1 (It is only name of configuration) 
    * Hostname => example_server_1.com (url of your server) 
    * Username => ec2-user (for amazon) 
    (Click "Add Server" button) 
    * Name => Server_2 (It is only name of configuration) 
    * Hostname => example_server_2.com (url of your server) 
    * Username => ec2-user (for amazon) 

**2. Job Configuration** 
Open Job => Configure => 
1. Add String Parameter "Name=Server" 
2.Check "Send files or execute commands over SSH" => SSH Server section 
2.1 Name=server_1; 
Exec_command=cd temp_directory(for example); 
Click "Advanced" => Label=server_1; 
2.2 Click "Add Server"; 
Name=server_2; 
Exec_command=cd temp_directory(for example); 
Click "Advanced" => Label=server_2; 
2.3 In front of button "Add Server" click "Advanced"; Check "Parameterized publishing" => Parameter_name=Server 

**3. Job running** 

Run job and set for example server_2. You will see in log: 

    SSH: Skipping [server_1] - Label server_1 does not match expression server_2 
    SSH: Publishing to [server_2] - Label server_2 matches expression server_2 
    SSH: Connecting from host [ip-10-0-0-37] 
    SSH: Connecting with configuration [server_2] ... 

It is seems that if you set server_2 job will try to compare parameter "Server" (you defined it before job starts) and labels in jobs. If label and parameter equals than exec commands in configuration. 

Hope it was helpfull. Cause I spent on it 5 hours. 
+0

非常感謝你的親愛的朋友,你這麼漂亮地解釋它,像一個魅力一樣工作。 –

+0

@JamesSelvakumar歡迎你) – IgorN

相關問題