Post-Commit Hook to trigger automatic Jenkins Build

后端 未结 2 2189
盖世英雄少女心
盖世英雄少女心 2020-12-28 21:01

I know that there are many similar postings, but I have not found a solution, and the advice and solutions presented in the other posts don\'t quite jive with what I\'m seei

2条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-28 21:12

    I tried to get the svn plugin examples to work, but no luck. Instead I used the build token root plugin and this works without having to poll.

    https://wiki.jenkins-ci.org/display/JENKINS/Build+Token+Root+Plugin

    Build Triggers > Trigger builds remotely option > give it a token

    On VisualSVN server add this to the post-commit hook:

    SET CSCRIPT=%windir%\system32\cscript.exe
    SET VBSCRIPT=C:\Repositories\post-commit-hook-jenkins.vbs
    "%CSCRIPT%" "%VBSCRIPT%" "MyJobName" "MyTokenFromBuildTrigger"
    

    For post-commit-hook-jenkins.vbs:

    Set args = WScript.Arguments
    JobName = args.Item(0)
    Token = args.Item(1)
    
    'URL to open....
    sUrl = "http://MyJenkinsServer.MyCompany.com/buildByToken/build?job=" + JobName + "&token=" + Token
    'POST Request to send.
    sRequest = ""
    
    HTTPPost sUrl, sRequest
    
    Function HTTPPost(sUrl, sRequest)
      set oHTTP = CreateObject("Microsoft.XMLHTTP")
      oHTTP.open "POST", sUrl,false
      oHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
      oHTTP.setRequestHeader "Content-Length", Len(sRequest)
      oHTTP.send sRequest
      HTTPPost = oHTTP.responseText
     End Function 
    

提交回复
热议问题