Jenkins脚本化或声明性管道-如何设置职位描述文本

时间:2019-03-09 17:09:59

标签: jenkins jenkins-pipeline

有人知道如何为Jenkins的脚本化或声明性管道中定义的作业设置描述文本吗? 原因:我想添加一些有关这项工作的有意义的文字(小的文档)。

2 个答案:

答案 0 :(得分:3)

此解决方案通过jenkins中的常规脚本更改作业项目的描述。我只在自由式工作中使用过它,但我认为它也应该在脚本管道中工作:

import jenkins.model.*
final jenkins   = Jenkins.getInstanceOrNull()
final myJob     = jenkins.getItem("MyJobName")

description = "<h1 style=\"color:green\">The newest build has number ${env.BUILD_NUMBER}</h1>"
myJob.setDescription(description)
myJob.save()

此解决方案更改了版本说明: 使用“ currentbuild”全局变量。

即声明性管道:

script { currentbuild.description = 'New Description' }

在脚本化管道中也可以使用相同的方法:)

参考:https://opensource.triology.de/jenkins/pipeline-syntax/globals

答案 1 :(得分:2)

用于声明式管道

from copy import deepcopy
def merge_lists(list_Incoming, list_Outgoing):
    # create dictionary from list_Incoming:
    dict1 = {(record['Venue'], record['Date']): record  for record in list_Incoming}

    #compare elements in list_Outgoing to those on list_Incoming:

    result = {}
    for record in list_Outgoing:
        ckey = record['Venue'], record['Date']
        new_record = deepcopy(record)
        if ckey in dict1:
            for key, value in dict1[ckey].items():
                if key in ('Venue', 'Date'):
                    # Do not merge these keys
                    continue
                # Dict's "setdefault" finds a key/value, and if it is missing
                # creates a new one with the second parameter as value
                new_record.setdefault(key, {}).update(value)

        result[ckey] = new_record

    # Add values from list_Incoming that were not matched in list_Outgoing:
    for key, value in dict1.items():
        if key not in result:
            result[key] = deepcopy(value)

    return list(result.values())

res = merge_lists(list_Incoming, list_Outgoing)
print(res)
[{'10': {'OutgoingCount': 5, 'IncomingCount': 45}, 
  'Date': '20190101', 
  'Venue': 'Beach', 
  '08': {'IncomingCount': 93}, 
  '07': {'OutgoingCount': 30}
 },

 {'10': {'OutgoingCount': 15}, 
   'Date': '20190103', 
   'Venue': 'Hotel', 
   '07': {'OutgoingCount': 5}
 }, 

 {'10': {'IncomingCount': 3}, 
  'Date': '20190101', 
  'Venue': 'Hotel', 
  '08': {'IncomingCount': 15}
 }]

用于脚本化

script {
       currentBuild.description = "description env var if required :${env.ver}"
}