modified version of jenkins debian glue (https://github.com/mika/jenkins-debian-glue) for devuan
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

118 lines
3.5 KiB

  1. #!/bin/bash
  2. # Purpose: Trigger Jenkins autobuild
  3. # to be invoked via $SVN/hooks/post-commit via
  4. # bash /usr/bin/trigger_jenkins "$1"
  5. if [ "$#" -lt 1 ] ; then
  6. echo "Usage: $0 <REPOS> [SVN_REVISION]" >&2
  7. exit 1
  8. fi
  9. REPOS="$1"
  10. if [ -n "$2" ] && [ "$2" -gt 0 ] ; then
  11. REV_OPTS="--revision $2"
  12. fi
  13. if ! [ -r "${REPOS}"/format ] ; then
  14. echo "Specified repository ${REPOS} does not look like a repository." >&2
  15. exit 1
  16. fi
  17. # defaults
  18. trigger_token="secret" # ADJUST!
  19. trigger_cause="svn_commit_triggered"
  20. trigger_url="https://jenkins.example.org" # ADJUST!
  21. tags_url="https://jenkins.example.org:5000" # ADJUST!
  22. enable_tag_trigger=false
  23. trigger_build() {
  24. if [ -n "$1" ] ; then
  25. trigger_project="$1"
  26. else
  27. echo "Error: no trigger_project specified, can not trigger project." >&2
  28. return 1
  29. fi
  30. if curl --insecure --max-time 5 --connect-timeout 5 \
  31. --data-urlencode "token=${trigger_token}" \
  32. --data-urlencode "cause=${trigger_cause}" \
  33. --data-urlencode "branch=${trigger_branch}" \
  34. "${trigger_url}/job/${trigger_project}/buildWithParameters" ; then
  35. echo "Trigger autobuild at ${trigger_url}/job/${trigger_project}/lastBuild/"
  36. else
  37. echo "Could not trigger autobuild of trunk documentation at jenkins."
  38. fi
  39. # add new tag versions to release dashboard
  40. if $enable_tag_trigger ; then
  41. project="${trigger_project%%-source}"
  42. tag="${trigger_branch##tags/}"
  43. if curl --insecure --max-time 5 --connect-timeout 5 \
  44. "${tags_url}/tags/register/${project}/${tag}" ; then
  45. echo "Registered new tag ${tag} of project ${project} to release dashboard."
  46. else
  47. echo "Could not register tag ${tag} of project ${project} to release dashboard."
  48. fi
  49. fi
  50. }
  51. for dir in $(/usr/bin/svnlook dirs-changed "$REPOS" $REV_OPTS) ; do
  52. case "$dir" in
  53. # only the "main" directory contains projects we care about
  54. # you *DEFINITELY* need to adjust that according to your needs
  55. main/*)
  56. # dynamically calculate trigger information
  57. SVN_PROJECT="${dir##main/}"
  58. project="${SVN_PROJECT%%/*}"
  59. branch="${SVN_PROJECT#*/}"
  60. trigger_branch="${branch%%/*}"
  61. # correctly handle tags and branchs
  62. case "$branch" in
  63. branches/*)
  64. trigger_branch=ignore
  65. ;;
  66. tags/*)
  67. # sort: try to move the shortest line to the beginning
  68. # grep: make sure we only get _U/U (updates) and _A/A (additions)
  69. # head: limit the result to just one project
  70. # awk: print directory name only
  71. trigger_branch=$(/usr/bin/svnlook changed "$REPOS" $REV_OPTS | sort -u | grep '^[_]*U\|^[_]*A.*/tags/' | head -1 | awk '{print $2}')
  72. trigger_branch="${trigger_branch##*tags/}"
  73. trigger_branch="${trigger_branch%%/*}"
  74. trigger_branch="tags/${trigger_branch}"
  75. enable_tag_trigger=true
  76. ;;
  77. esac
  78. if [ "$trigger_branch" = "ignore" ] ; then
  79. echo "Change(s) in a branch identified, not triggering build therefore."
  80. exit 0
  81. fi
  82. if [ -z "$trigger_branch" ] || [ "$trigger_branch" = "tags/" ] ; then
  83. echo "No valid branch for triggering found [${trigger_branch}], skipping request." >&2
  84. exit 1
  85. fi
  86. case "$project" in
  87. # projects without according *-source job
  88. documentation)
  89. trigger_project="documentation"
  90. ;;
  91. *)
  92. trigger_project="${project}-source"
  93. ;;
  94. esac
  95. ;;
  96. esac
  97. trigger_build "$trigger_project"
  98. done
  99. # EOF
  100. # vim:foldmethod=marker ts=2 ft=sh ai expandtab sw=2