Start Jenkins build using batch script

后端 未结 6 1992
挽巷
挽巷 2020-12-15 23:43

I am working with a Jenkins build server to run synthesis/simulation for FPGAs. Right now I have nightly builds and can start the build manually in Jenkins browser interface

6条回答
  •  心在旅途
    2020-12-15 23:56

    I've googled across many addresses and the working result can be found here:

    #!/bin/bash
    TOKEN='jenkins-user-token'
    USER='my-username'
    SERVER="http://your.server.address"
    
    #jenkins job parameters
    PARAMF=$1
    SECONDPARAM=$2
    
    # retrieve the crumb that we need to pass in the header
    CRUMBS=$(curl -s -X GET -u $USER:$TOKEN ${SERVER}/crumbIssuer/api/json  | jq -c '. | .crumb ')
    curl --user $USER:$TOKEN  -H "Jenkins-Crumb:${CRUMBS}" -X POST  "${SERVER}/view/MyView/job/JobName/buildWithParameters?TOKEN=${TOKEN}&PARAMETERONE=${PARAMF}&PARAMETERTWO=${SECONDPARAM}"
    
    

    The steps script does:

    1. get the breadcrumb
    2. call jenkins to execute a job with multiple parameters

    you can save this script as jenkins-job-cli.sh and call it

    chmod +x jenkins-job-cli.sh
    ./jenkins-job-cli.sh first-parameter second-parameter
    

    Hope this help.

    Cheers,

    Leslie

提交回复
热议问题