Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何生成changelog:git日志(自上次Hudson构建以来)?_Git_Bash_Continuous Integration_Hudson_Phing - Fatal编程技术网

如何生成changelog:git日志(自上次Hudson构建以来)?

如何生成changelog:git日志(自上次Hudson构建以来)?,git,bash,continuous-integration,hudson,phing,Git,Bash,Continuous Integration,Hudson,Phing,我用Phing在Hudson做后期构建任务 我想生成包含自上次成功Hudson构建以来所有提交的变更日志。但是看起来Hudson和Hudson的Git插件都没有提供%last\u build\u time%变量 这将是一个令人满意的解决方案,(但如何获得时间?) 目前我看到的唯一方法是从作业xml文件中提取它,但我不知道使用Phing是否可行 如何生成更改日志?我已使用bash提取了上次成功生成日期: git log --pretty="%s" --since="`date -r ./../la

我用Phing在Hudson做后期构建任务

我想生成包含自上次成功Hudson构建以来所有提交的变更日志。但是看起来Hudson和Hudson的Git插件都没有提供
%last\u build\u time%
变量

这将是一个令人满意的解决方案,(但如何获得时间?)

目前我看到的唯一方法是从作业xml文件中提取它,但我不知道使用Phing是否可行


如何生成更改日志?

我已使用bash提取了上次成功生成日期:

git log --pretty="%s" --since="`date -r ./../lastSuccessful/build.xml "+%F %T"`"

(在xml文件中,我必须将
替换为
"e;
实体)。

@takeshin的答案是,如果您可以访问build.xml文件,则答案是正确的,但这可能会中断,尤其是在从节点上构建时(因为从节点没有引用的build.xml)

不用担心,因为您可以通过Jenkins的远程访问api直接访问这些信息:

例如:

http://<host>/jenkins/job/<job_name>/lastSuccessfulBuild/api/xml
http:///jenkins/job//lastSuccessfulBuild/api/xml
(将为您提供xml内容……例如,您可以用json替换xml以取回json内容,而不是xml)

请注意,如果您已将Jenkins实例设置为需要身份验证,则可能需要使用身份验证。同样,请不要担心:

然后,就可以简单地解析XML以获取所需内容。可能是这样的:

curl --silent --user $USER:$API_TOKEN $URL | grep "<lastBuiltRevision>" | sed 's|.*<lastBuiltRevision>.*<SHA1>\(.*\)</SHA1>.*<branch>.*|\1|'
curl--silent--user$user:$API|u TOKEN$URL | grep”“| sed的|.*.\(.*).*..*.|\1 |'
因此,总而言之,您可以使用一个(相对)简单的shell脚本从Jenkins检索最后一个好的修订哈希:

#!/bin/sh
GIT_LOG_FORMAT="%ai %an: %s"
USER=<username>
API_TOKEN=<api_token>

LAST_SUCCESS_URL_SUFFIX="lastSuccessfulBuild/api/xml"
#JOB_URL gets populated by Jenkins as part of the build environment
URL="$JOB_URL$LAST_SUCCESS_URL_SUFFIX"

LAST_SUCCESS_REV=$(curl --silent --user $USER:$API_TOKEN $URL | grep "<lastBuiltRevision>" | sed 's|.*<lastBuiltRevision>.*<SHA1>\(.*\)</SHA1>.*<branch>.*|\1|')
# Pulls all commit comments since the last successfully built revision
LOG=$(git log --pretty="$GIT_LOG_FORMAT" $LAST_SUCCESS_REV..HEAD)
echo $LOG
!/bin/sh
GIT_LOG_FORMAT=“%ai%an:%s”
使用者=
API_令牌=
LAST_SUCCESS_URL_SUFFIX=“lastSuccessfulBuild/api/xml”
#作业URL由Jenkins作为构建环境的一部分填充
URL=“$JOB\u URL$LAST\u SUCCESS\u URL\u后缀”
LAST_SUCCESS_REV=$(curl--silent--user$user:$API_TOKEN$URL | grep”“| sed的|.*.\(.*)....*.|\1 |')
#提取自上次成功生成修订以来的所有提交注释
LOG=$(git LOG--pretty=“$git\u LOG\u FORMAT”$LAST\u SUCCESS\u REV..HEAD)
echo$LOG
干杯

利维

#!/bin/sh
GIT_LOG_FORMAT="%ai %an: %s"
USER=<username>
API_TOKEN=<api_token>

LAST_SUCCESS_URL_SUFFIX="lastSuccessfulBuild/api/xml"
#JOB_URL gets populated by Jenkins as part of the build environment
URL="$JOB_URL$LAST_SUCCESS_URL_SUFFIX"

LAST_SUCCESS_REV=$(curl --silent --user $USER:$API_TOKEN $URL | grep "<lastBuiltRevision>" | sed 's|.*<lastBuiltRevision>.*<SHA1>\(.*\)</SHA1>.*<branch>.*|\1|')
# Pulls all commit comments since the last successfully built revision
LOG=$(git log --pretty="$GIT_LOG_FORMAT" $LAST_SUCCESS_REV..HEAD)
echo $LOG