Answer to your question and how I configured my process:
1. Configuring Jenkins
- Install Publish over SSH plugin
- Configure Jenkins => System Configuration
Publish over SSH section
2. Job Configuration
- Open Job => Configure
- Check This project is parameterized
Add Choice Parameter
- Name: server
Choices:
server_1
server_2
- Select Send files or execute commands over SSH => SSH Server section
- Name: select your first server
- Enter Transfer Set data (Source files and/or Exec_command)
- Click Advanced
- Label: server_1 (this is the first choice of your choice parameter)
- Click Add Server
- Name: select your second server
- Enter Transfer Set data (Source files and/or Exec_command)
- Click Advanced
- Label: server_2 (this is the second choice of your choice parameter)
- In front of button Add Server, click Advanced
- Check Parameterized publishing
- Parameter name: server (this is the name of your choice parameter)
3. Job Running
Run job and select for example Server => 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] ...
Explanation
The plugin compares the value of the parameter named "Server" (which you selected before job starts) with the labels that you have configured. If label and parameter match, then the SSH commands are executed.
Hope it was helpful. Cause I spent on it 5 hours.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…