Jenkins管道始终以“何时”条件跳过Git标签的阶段

时间:2019-12-05 07:50:06

标签: jenkins jenkins-pipeline

在声明性多分支Jenkins管道中,我只想在存在Git标签的情况下运行一个阶段。出于测试原因,我建立了一个简单的虚拟管道。但是,import branca.colormap from collections import defaultdict import folium import webbrowser from folium.plugins import HeatMap map_osm = folium.Map(llocation=[35,110],zoom_start=1) steps=20 colormap = branca.colormap.linear.YlOrRd_09.scale(0, 1).to_step(steps) gradient_map=defaultdict(dict) for i in range(steps): gradient_map[1/steps*i] = colormap.rgb_hex_str(1/steps*i) colormap.add_to(map_osm) #add color bar at the top of the map HeatMap(data1,gradient = gradient_map).add_to(map_osm) # Add heat map to the previously created map file_path = r"C:\\test.html" map_osm.save(file_path) # Save as html file webbrowser.open(file_path) # Default browser open 阶段始终被跳过。我检查了是否存在Git标签,并按下了该标签,但这似乎没有任何效果。

Jenkinsfile

demo

Jenkins build的控制台输出

pipeline {
    agent any

    environment {
        APP_NAME = 'myapp'
    }

    stages {
        stage('Demo') {
            when { buildingTag() }
            steps {
                echo "Found a tag..."
            }
        }
    }
}

克隆存储库的日志输出

[Pipeline] }
[Pipeline] // stage
[Pipeline] withEnv
[Pipeline] {
[Pipeline] withCredentials
[Pipeline] {
[Pipeline] withEnv
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Demo)
Stage "Demo" skipped due to when conditional
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // withCredentials
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline

Jenkins job configuration

1 个答案:

答案 0 :(得分:1)

请注意以下几点:

  

检出修订版1bcf713882dbdba6b8007e0f6c23b44207cbab1e(管理员)

这表明代码正在签出分支,而不是标签。您需要签出标签才能使其正常工作。输出将类似于:

  

签出修订版a8deb8ef28d4b83e5f146afe132ac21dee47f225(TEST_TAG)

从技术上讲 tag buildingTag 条件check是否设置了TAG_NAME环境变量( tag 还会检查该值) 。当Git插件签出标签时,此设置会自动设置,但签出分支时将不可用,即使同一提交上有标签也是如此。

由于您似乎正在使用多分支管道,因此需要从“标签”选项卡开始构建以使其运行。