8

我正在尝试设置我正在触发的构建的构建描述,因为我正在开始构建,但到目前为止我还没有运气。

我遇到了一个解决方案(将文本添加到由 Jenkins 远程 API 触发的构建页面),我有点让它以这种方式工作(第一个命令将启动构建,第二个命令将设置最后一个的描述建造):

curl -v -X POST "http://[myServer]/job/[jobName]/build"
curl -v -X POST "http://[myServer]/job/[jobName/lastBuild/submitDescription" --data-urlencode "description=test description"

但是,问题是,如果我刚刚启动的构建被排队/没有立即启动,“lastBuild”将不会引用我刚刚启动的构建,而是它之前的构建(仍在构建中)。

所以我尝试了这样的事情:

payload='json={""description"":""test description""}'
curl -v -X POST -H "Content-Type: application/json" -d $payload "http://[myServer]/job/[jobName]/build"

但它实际上并没有设置描述。

有什么想法可以实现吗?

我找到的其他解决方案,但我并不满意:

4

5 回答 5

13

您始终可以拥有一个变量,并在初始调用时将构建描述传递给变量。然后在构建结束时,将变量输出到控制台并使用Description Setter plugin捕获。

编辑以澄清:

  • 安装描述设置器插件
  • 在 Job Configuration 中,配置一个 String 参数,将其命名为“ MyDescription ”,将默认值留空。
  • 在构建步骤中的某处,根据您的操作系统,“执行 Shell ”或“执行 Windows 批处理命令”类型echo Desc: $MyDescription或。echo Desc: %MyDescription%
  • 在 Post-Build 步骤中,选择“ Set Build Description ”。
    • 正则表达式设置为^Desc: (.*)
    • 描述设置为\1
  • 从命令行触发:

curl -v -X POST --data-urlencode "MyDescription=This is my desc" "http://[myServer]/job/[jobName]/buildWithParameters"
(上面是一行)

于 2015-02-17T17:45:58.883 回答
3

我也有同样的需求——在构建开始时立即设置构建描述。
请注意,构建描述设置器插件是作为构建后操作激活的,这对我来说为时已晚。
我解决它的方法是对作业配置和 Python 脚本(但可以是任何语言)进行细微更改:

  • 在作业配置中添加 UUID 参数
  • 创建了一个脚本来提交和设置描述

该脚本执行以下操作:

  1. 提交构建时,生成一个 uuid 值(唯一的,对吗?)并填充 UUID 参数
  2. 轮询 Jenkins 作业(通过 REST API 获取其 JSON),循环所有正在运行的构建,找到我的(通过 UUID 的已知值)。通过超时限制轮询,所以我们不会永远挂起
  3. 使用 Jenkins Java CLI 设置描述(命令' set-build-description ')

一直有效,除非构建排队(没有可用的免费执行程序)并且上面设置的超时到期 - 我无能为力。

于 2016-04-11T11:31:45.063 回答
0

另一种解决方案,使用“执行 Groovy 系统脚本”:

def currentBuild = Thread.currentThread().executable
def FOO = build.buildVariableResolver.resolve('FOO')
currentBuild.setDescription(FOO)
于 2016-10-05T13:04:00.160 回答
0

对于那些对使用 Jenkins UI 感兴趣的人,我正在尝试:

  1. https://wiki.jenkins-ci.org/display/JENKINS/Build+Name+Setter+Plugin
  2. https://wiki.jenkins-ci.org/display/JENKINS/Groovy+Postbuild+Plugin

Postbuild 插件功能更强大,但需要 Groovy 修补和 perms。

于 2016-01-06T01:11:19.703 回答
-4

我的下载:

String urlDownload = "https://dl.dropbox.com/s/ex4clsfmiu142dy/test.zip?token_hash=AAGD-XcBL8C3flflkmxjbzdr7_2W_i6CZ_3rM5zQpUCYaw&dl=1";     
DownloadManager.Request request = new  DownloadManager.Request(Uri.parse(urlDownload)); 
request.setDescription("Testando"); request.setTitle("Download"); 
request.allowScanningByMediaScanner(); 
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); 
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "teste.zip"); 
final DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); 
final long downloadId = manager.enqueue(request); 
final ProgressBar mProgressBar = (ProgressBar) findViewById(R.id.progressBar1); 

new Thread(new Runnable() { 

    @Override 
    public void run() { 
        boolean downloading = true; 
        while (downloading) { 
            DownloadManager.Query q = new DownloadManager.Query(); 
            q.setFilterById(downloadId); 
            Cursor cursor = manager.query(q); 
            cursor.moveToFirst(); 
            int bytes_downloaded = cursor.getInt(cursor .getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR)); 
            int bytes_total = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES)); 
            if (cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS)) == DownloadManager.STATUS_SUCCESSFUL) { 
                downloading = false; 
            } 
            final double dl_progress = (bytes_downloaded / bytes_total) * 100; 
            runOnUiThread(new Runnable() { 
                @Override 
                public void run() {
                    mProgressBar.setProgress((int) dl_progress); 
                } 
            }); 
            Log.d(Constants.MAIN_VIEW_ACTIVITY, statusMessage(cursor)); 
            cursor.close(); 
        } 
    } 
}).start();

我的 statusMessage 方法:

private String statusMessage(Cursor c) { 
    String msg = "???"; 
    switch (c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS))) { 
        case DownloadManager.STATUS_FAILED: 
            msg = "Download failed!"; 
            break; 
        case DownloadManager.STATUS_PAUSED: 
            msg = "Download paused!"; 
            break; 
       case DownloadManager.STATUS_PENDING: 
            msg = "Download pending!"; 
            break; 
       case DownloadManager.STATUS_RUNNING: 
            msg = "Download in progress!"; 
            break; 
       case DownloadManager.STATUS_SUCCESSFUL: 
            msg = "Download complete!"; 
            break; 
       default: 
            msg = "Download is nowhere in sight"; 
            break; 
   } 
   return (msg); 
}
于 2016-10-05T13:06:11.450 回答