Jenkins notifyCommit 触发器不起作用?

cze*_*uya 4 svn jenkins

我已经处理这个问题几个小时了,似乎我做错了什么。

首先,svn 的 post-commit 钩子已经可以工作了,因为我已经能够看到日志了,这里是 post-commit 的代码:

#!/bin/sh

REPOS="$1"
REV="$2"
UUID=`svnlook uuid $REPOS`

/bin/echo "$REPOS $REV $UUID" >> /var/subversion/svn-post-commit.out
Run Code Online (Sandbox Code Playgroud)

请注意,要使其工作,您需要执行 chmod 777 以提交后并执行 chown www-data:www-data 到 svn 存储库。

不起作用的是 jenkins notifyCommit,它会在 jenkins 中自动构建项目:

/usr/bin/wget \
  --header "Content-Type:text/plain;charset=UTF-8" \
  --post-data "'svnlook changed --revision $REV $REPOS'" \
  --output-document "-" \
  --timeout=2 \
  http://localhost:8080/subversion/${UUID}/notifyCommit?rev=$REV
Run Code Online (Sandbox Code Playgroud)

我也尝试通过 curl 调用

curl --data "rev=4" http://localhost:8080/subversion/c8bb87ec-9a19-4975-ab9d-8b15741e6d7e/notifyCommit
Run Code Online (Sandbox Code Playgroud)

没有错误,但詹金斯没有建立。

有任何想法吗?

卷发的回复:

* About to connect() to 10.1.1.133 port 8080 (#0)
*   Trying 10.1.1.133... connected
> POST /subversion/c8bb87ec-9a19-4975-ab9d-8b15741e6d7e/notifyCommit HTTP/1.1
> User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3
> Host: 10.1.1.133:8080
> Accept: */*
> Content-Length: 5
> Content-Type: application/x-www-form-urlencoded
> 
* upload completely sent off: 5out of 5 bytes
< HTTP/1.1 200 OK
< Server: Winstone Servlet Engine v0.9.10
< Connection: Close
< Content-Type: text/html;charset=UTF-8
< Date: Mon, 22 Oct 2012 05:48:49 GMT
< X-Powered-By: Servlet/2.5 (Winstone/0.9.10)
< 
* Closing connection #0
Run Code Online (Sandbox Code Playgroud)

谢谢,
czetsuya

Sta*_*tan 5

有两种方法可以在 Jenkins 中远程启动构建,我已经成功使用了它们。(示例适用于 shell 脚本)

一种是使用 URL 并启动特定作业:

方法一:

WGET="/usr/bin/wget"
JENKINS_JOB="Your-Job-Name"
$WGET http://ip:port/job/$JENKINS_JOB/build?token=sampletocken
Run Code Online (Sandbox Code Playgroud)

如果您尝试启动已参数化的作业,则可以通过这种方式指定参数(否则作业将无法启动):

$WGET http://ip:port/job/$JENKINS_JOB/buildWithParameters?param-name=param-value&token=sampletocken
Run Code Online (Sandbox Code Playgroud)

带有 token=sampletoken 的部分不是必需的,但增加了一点安全性。您可以在“远程触发构建”下的作业配置中配置令牌。

另一种方法是使用 Jenkins subversion API:

方法二:

# REPOS is the local path of the repository.
# REV is the revision that we want to build.
# SERVER is the full URL of Jenkins.
# UUID of the repository (it will be used to identify it to Jenkins)

REPOS="$1"
REV="$2"
SERVER="http://ip:port"
UUID=`svnlook uuid $REPOS`

$WGET \
  --header "Content-Type:text/plain;charset=UTF-8" \
  --post-data "`svnlook changed --revision $REV $REPOS`" \
  --output-document "-" \
  --timeout=2 \
  $SERVER/subversion/${UUID}/notifyCommit?rev=$REV
Run Code Online (Sandbox Code Playgroud)

为了让这一切正常工作,您必须为 Jenkins 中的匿名用户授予适当的权限。但是,这可能是您不想做的事情,因为它会引起安全问题。

验证

为了使其更安全,您可以创建一个单独的用户,该用户将在脚本中用于向 Jenkins 进行身份验证。将此用户配置为拥有一些您将在脚本中使用的“API 令牌”。(不要忘记删除匿名用户的所有权限)

然后您需要将以下内容添加到您的 wget 命令中:

wget --auth-no-challenge --http-user=user --http-password=apiToken
Run Code Online (Sandbox Code Playgroud)

“--auth-no-challenge”用于避免“403 forbidden”错误。您还可以将其他令牌添加到 URL,如前一个示例所示。

事实证明,最后一部分对我来说是有问题的,因此可能需要反复试验......


cze*_*uya 0

我找到了解决方法,但它并不优雅。我使用 jenkins cli 手动调用构建。我已经记录了我在这里所做的事情:

http://czetsuya-tech.blogspot.com/2012/10/an-alternative-way-of-invoking-jenkins.html