访问Jenkins管道作业上的SCM(Git)变量

时间:2016-03-08 17:23:34

标签: git jenkins jenkins-workflow

这是我的管道代码:

def new_sheet(self,sheetnm,sheetdata):
    self.ws = self.wb.add_worksheet(sheetnm)
    logging.info(self.ws)
    metadata = sheetdata[1]
    head = (colh[0] for colh in metadata)
    self.ws.write_row(0,0,head)
    rows = sheetdata[0]
    for ix,row in enumerate(rows):
        self.ws.write_row(ix+1,0,row)            

def new_chart(self,sheetnm,ctitle,xtitle,ytitle,rows,cols):
    self.cs = self.wb.add_chartsheet(sheetnm+"_chart")
    chart = self.wb.add_chart({'type': 'bar'})
    chart.set_title({'name': ctitle})
    for row in range(1,rows):
        chart.add_series({'categories':[sheetnm,0,1,0,cols-1],'values':[sheetnm,row,1,row,cols-1],'name':[sheetnm,row,0,row,0]})
    chart.set_x_axis({'name': xtitle})
    chart.set_y_axis({'name': ytitle})
    self.cs.set_chart(chart)

构建结果如下:

node ('master') {
    git url: "$GIT_REPO_URL", branch: "$GIT_BRANCH"
    echo env.GIT_COMMIT
    echo env.GIT_BRANCH
    echo env.GIT_REVISION
}

未填充env变量env.GIT_COMMIT,env.GIT_BRANCH。这些值是否可用于其他变量?

1 个答案:

答案 0 :(得分:19)

以下是如何获取GIT_COMMIT - https://github.com/jenkinsci/pipeline-examples/blob/master/pipeline-examples/gitcommit/gitcommit.groovy

的示例

您也可以将其扩展为公开GIT_BRANCH。此脚本来自cloudbees管理的工作流示例git repo。如果您添加了检索GIT_BRANCH变量的功能,也许您可​​以发送拉取请求。