Post-Commit Hook to trigger automatic Jenkins Build

后端 未结 2 2090
盖世英雄少女心
盖世英雄少女心 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 
    
    0 讨论(0)
  • 2020-12-28 21:13

    The article you linked says

    Jobs on Jenkins need to be configured with the SCM polling option to benefit from this behavior. This is so that you can have some jobs that are never triggered by the post-commit hook (in the $REPOSITORY/hooks directory), such as release related tasks, by omitting the SCM polling option. The configured polling can have any schedule (probably infrequent like monthly or yearly). The net effect is as if polling happens out of their usual cycles.

    and

    For this to work, your Jenkins has to allow anonymous read access (specifically, "Job > Read" access) to the system. If access control to your Jenkins is more restrictive, you may need to specify the username and password, depending on how your authentication is configured.

    Does you server meets this restrictions?

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