LoginSignup
0
0

More than 5 years have passed since last update.

同一ホスト内Sphinxドキュメント間のリンク切れをJenkinsでチェックする

Posted at

複数のSphinxドキュメントを作っていて、sphinx.ext.extlinksを使って他のSphinxドキュメントにリンクしていたりすると、
開発時に割とリンク切れが起きる。
そのリンク切れをJenkinsでチェックする方法。ただし、サーバ内のリンク切れのみ。

ビルドを以下のように設定している。
Windowsバッチでwgetしているのは、JenkinsがWindows Serverにあるからで、
判定をGroovyにしているのは、Jenkinsでラクにスクリプトを動かせるから。
当然、これを1つのシェルスクリプトでやっても良いと思う。

Windowsバッチファイル

C:\z\wget\bin\wget.exe --spider --recursive --no-directories --no-verbose --no-parent http://hoge.com/docs/ > wget.log 2>&1
type wget.log

Execute Groovy script

new File("${System.getenv('WORKSPACE')}/wget.log").eachLine {
  if ((it =~ /^Found.*$/).find()) {
    def errors = it.replace("Found ", "").replace(" broken links.", "")
    if (errors == "no") {
      System.exit(0)
    } else {
      System.exit(1)
    }
  }
}

安易な判定方法をしてるし、ビルドのコンソール出力を見ないと切れてる箇所は分からないけど、最低限リンク切れがあればビルド失敗、なければ成功が実現できる。
これを1時間に1回ぐらいで実行するようにしておくと、意外と役に立った。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0