在Jenkins "Publish over Ssh"插件中,如何使用Label(高级选项)又称参数化发布功能。我如何使用标签字段。我在Label字段中放了什么。我是否需要设置一个变量名称(我可以从构建参数中读取)具有机器名称。我尝试了同样的事情这就是我所做的:
我有一个机器名称QA_1,我有一个变量jenkins构建$ MC_NAME指向XXX。我在LABEL字段中输入了$ MC_NAME。但令我惊讶的是Jenkins正在向QA_1机器发布,而不管$ MC_NAME变量的值是多少。
有些人可以通过在Jenkins的“Publish over Ssh”插件中使用LABEL来告诉我控制哪台机器发布/运行脚本的确切步骤
您应该启用“参数化发布”并通过单击构建配置中“添加构建后操作”按钮之前的最后一个“高级...”按钮来指定构建参数名称(例如,我使用后构建操作部分)。
例如。 “构建参数名称”= SSH_SERVER
。然后应该有SSH_SERVER
构建参数与regexp匹配ssh服务器标签。
在您的情况下,SSH_SERVER
构建参数应设置为XXX,之后SSH发布应仅针对QA_1服务器发生。
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.