jenkins_api_client icon indicating copy to clipboard operation
jenkins_api_client copied to clipboard

File parameter

Open onknows opened this issue 10 years ago • 10 comments

Is it possible to start a job and submit a file as parameter for the job?

Is there some documentation for example on the use of job_params?

onknows avatar May 06 '14 15:05 onknows

Yes it's possible, you can build a job as follows:

client = JenkinsApi::Client.new(.....)

job = JenkinsApi::Client::Job.new(client)

job.build(
  your_job_name,
  {
    :param_1 => param_1_value,
    :param_2 => param_2_value,
    :param_n => param_3_value
  },
  false
)

You can check the build method https://github.com/arangamani/jenkins_api_client/blob/master/lib/jenkins_api_client/job.rb#L762, don't know about documentation on this topic

0mega avatar May 06 '14 15:05 0mega

@0mega is correct. You can pass in parameters as a Hash. You just need to know the name of the parameter. I don't think I have any examples documented anywhere, I will try to add some.

arangamani avatar May 06 '14 18:05 arangamani

Unclear is what the param name should be. In Jenkins the file parameters does not have a name. Should it be file0?

Also, should we provide the path to the file or a file object. It is not clear.

onknows avatar May 07 '14 06:05 onknows

I tried it in very many ways, none work. No job is started, no error is reported.

onknows avatar May 07 '14 07:05 onknows

At this point I have another question, when doing a simple submit, I would like to get the build number. This was working but it stopped working. Requests return immediately without build number. Time out does not do much it seems for example opts = {'build_start_timeout' => 600000000} will also return without build number, immediately. Jobs are started and finish successfully. I suppose that the build_start_timeout is not implemented yet?

onknows avatar May 07 '14 07:05 onknows

Regarding to file, you can convert your file content to base64 and pass it to jenkins as a regular string/text parameter.

Regarding the build number you can get it as follows

job = JenkinsApi::Client::Job.new(client)
build_number = job.get_current_build_number(your_job_name)

0mega avatar May 07 '14 08:05 0mega

@ostraaten Do you still have issues with this?

arangamani avatar Jun 23 '14 08:06 arangamani

@arangamani The file is not being uploaded to the Jenkins but getting the 302 as response code.

@client = JenkinsApi::Client.new(YAML.load_file(File.expand_path("#{Rails.root}/config/login.yml", __FILE__)))
@client.logger = Logger.new('./log/development.log')
job = JenkinsApi::Client::Job.new(@client)
job.build("ListVMs.vPCCustomer/",{name: "vcim-ui-tests/src/main/resources/testconfiguser.properties", file: "/home/logan/test_automation/Testconfiguser.properties"},  false)
Where:
name => JENKINS LOCATION WHERE I NEED TO REPLACE  the existing testconfiguser.properties file with my new file
file => Local file Path from my machine, which needs to be uploaded to jenkins

LOG : I, [2014-07-22T16:46:03.821670 #10482] INFO -- : Building job 'ListVMs.vPCCustomer/' with parameters: {:name=>"vcim-ui-tests/src/main/resources/testconfiguser.properties", :file=>"/home/logan/test_automation/Testconfiguser.properties"} I, [2014-07-22T16:46:03.822053 #10482] INFO -- : POST /job/ListVMs.vPCCustomer//buildWithParameters D, [2014-07-22T16:46:05.095018 #10482] DEBUG -- : HTTP Code: 302, Response Body:

loganathansellappa avatar Jul 22 '14 11:07 loganathansellappa

Yea looks like this gem doesn't handle files as parameters. To be able to support files you'd either have to do a lot of manual dance using NET::HTTP to create a multipart/form-data to upload the file content or switch NET::HTTP to farady or any rubygem that supports file uploads via post.

Reference for how the file parameter can be used in jenkins https://wiki.jenkins-ci.org/display/JENKINS/Remote+access+API

mbergmann avatar Mar 05 '15 06:03 mbergmann

We can even use RestClient across the board if there is a real need for it. I didn't use it in the initially to avoid the number of dependent gems.

arangamani avatar Mar 05 '15 08:03 arangamani