使用GitVersion生成Docker映像标签

时间:2019-07-09 09:29:33

标签: git docker azure-devops continuous-integration gitversion

我试图弄清楚如何使用GitVersion生成与docker兼容的build id,默认情况下gitversion使用的是这样的东西:

0.1.0-branchname.1+380

,但是+不能用于图像标签名称。我在GitVersion文档下找到的唯一合理的东西是NuGetVersionV2变量,它似乎确实将+替换为-,但我想知道如何对它进行更多控制gitversion如何为提交生成“偏移”

2 个答案:

答案 0 :(得分:0)

对于GitVersion task,基于测试结果,它会计算当前分支的所有提交,而不是基于先前的生成或缓存,而不管使用Microsoft托管还是自托管代理。

GitVersion任务会导出其他变量,因此我建议您可以将其他变量用作docker image标签而不是BuildId。

##[debug]Processed: ##vso[task.setvariable variable=GitVersion.Major;]0
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.Minor;]1
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.Patch;]0
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.PreReleaseTag;]
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.PreReleaseTagWithDash;]
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.PreReleaseLabel;]
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.PreReleaseNumber;]
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.BuildMetaData;]17
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.BuildMetaDataPadded;]0017
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.FullBuildMetaData;]17.Branch.master.Sha.4515221c0e10f3bf3fa4038b9b25e2379080ddf1
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.MajorMinorPatch;]0.1.0
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.SemVer;]0.1.0
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.LegacySemVer;]0.1.0
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.LegacySemVerPadded;]0.1.0
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.AssemblySemVer;]0.1.0.0
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.AssemblySemFileVer;]0.1.0.0
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.FullSemVer;]0.1.0+17
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.InformationalVersion;]0.1.0+17.Branch.master.Sha.4515221c0e10f3bf3fa4038b9b25e2379080ddf1
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.BranchName;]master
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.Sha;]4515221c0e10f3bf3fa4038b9b25e2379080ddf1
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.ShortSha;]4515221
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.NuGetVersionV2;]0.1.0
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.NuGetVersion;]0.1.0
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.NuGetPreReleaseTagV2;]
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.NuGetPreReleaseTag;]
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.CommitsSinceVersionSource;]17
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.CommitsSinceVersionSourcePadded;]0017
##[debug]Processed: ##vso[task.setvariable variable=GitVersion.CommitDate;]2019-07-10

您还可以在GitVersion.yml中自定义格式。例如:

mode: ContinuousDelivery
assembly-informational-format: '{SemVer}-{ShortSha}'
branches: {}
ignore:
  sha: []

然后,在Docker任务(标签输入框)中使用 $(Gitversion.Informationalversion) (样本数据:0.1.0-0322edb)

enter image description here

答案 1 :(得分:0)

这就是我最终要做的:

var num;
$('#sel1').on('change', function(event) {
    alert("This is the value selected in solutions: " + $(this).val());
    num = $(this).val();
    var formHTML = $("#form1").html(); // Get the HTML content of '#form1'
    $('#form_container').html(''); // Clear the contents of form_container
    for(var i = 0; i < num; i++){
        var id = i + 1;
        $('#form_container').append('<form class="form-horizontal striped-rows b-form" id="form'+id+'">'+formHTML+'</form>');
    }
});

与此结合:

mode: ContinuousDeployment
assembly-informational-format: '{Major}.{Minor}.{Patch}-{PreReleaseLabel}-{ShortSha}'
branches: {}
ignore:
  sha: []