Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
598 views
in Technique[技术] by (71.8m points)

continuous integration - How to Control Parametrized publishing in Jenkins using Publish over SSH plugin's Label field

In Jenkins "Publish over Ssh" plugin how do I use the Label(Advanced options) aka Parameterized publishing feature. How do I use the label field. What do I put in the Label field. Do I need to put a variable name(one I can read from build param) that would have the Machine Name . I tried out the same Here is what I did:

I had a machine name QA_1 and I had one variable jenkins build $MC_NAME pointed to XXX . I entered $MC_NAME in the LABEL field. but to my surprise Jenkins was publishing to QA_1 machine irrespective of what the value of $MC_NAME variable.

Can some one PLease tell me the exact steps to control which machine to publish/run scripts by using LABEL filed in "Publish over Ssh" plugin in Jenkins

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Answer to your question and how I configured my process:

1. Configuring Jenkins

  1. Install Publish over SSH plugin
  2. Configure Jenkins => System Configuration
  3. Publish over SSH section

    • 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

  1. Open Job => Configure
  2. Check This project is parameterized
  3. Add Choice Parameter

    • Name: server
    • Choices:

       server_1
       server_2
      
  4. 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...