jenkins_api_client
jenkins_api_client copied to clipboard
File parameter
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?
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 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.
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.
I tried it in very many ways, none work. No job is started, no error is reported.
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?
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)
@ostraaten Do you still have issues with this?
@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:
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
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.