How can a Jenkins user authentication details be “passed” to a script which uses Jenkins API to create jobs?

前端 未结 7 653
别跟我提以往
别跟我提以往 2020-12-02 08:24

I have a script that delete and re-create jobs through curl HTTP-calls and I want to get rid of any hard-coded \"username:password\". E.g. curl -X POST $url --user use

相关标签:
7条回答
  • 2020-12-02 09:26

    If you want to write a script to automate creation of jobs using the Jenkins API, you can use one of the API clients to do that. A ruby client for Jenkins is available at https://github.com/arangamani/jenkins_api_client

    gem install jenkins_api_client
    
    require "rubygems"
    require "jenkins_api_client"
    
    # Initialize the client by passing in the server information
    # and credentials to communicate with the server
    client = JenkinsApi::Client.new(
      :server_ip => "127.0.0.1",
      :username => "awesomeuser",
      :password => "awesomepassword"
    )
    
    # The following block will create 10 jobs in Jenkins
    # test_job_0, test_job_1, test_job_2, ...
    10.times do |num|
      client.job.create_freestyle(:name => "test_job_#{num}")
    end
    
    # The jobs in Jenkins can be listed using
    client.job.list_all
    

    The API client can be used to perform a lot of operations.

    0 讨论(0)
提交回复
热议问题