我有一个在Jenkins中构建的应用程序,并且想要部署到Octopus。在执行此操作时,我必须创建一个发送到Octopus的发行版本。对于此次发布的版本我必须给一个号码(例如:"C:\Octopus\Octo.exe" create-release --project APP --version 4.8 --packageversion=4.8)
"C:\Octopus\Octo.exe" create-release --project APP --version 4.8 --packageversion=4.8
如何使版本号自动递增?(例如:我已经构建了应用程序,并在Octopus中创建了发行版本号4.8,下次创建应用程序时,我想创建发行版号4.9)
谢谢
您可以使用job属性存储版本,然后在每次运行时使用以下脚本对其进行更新(由“ Execute system groovy script”构建步骤执行):
import jenkins.model.Jenkins import hudson.model.* def jenkins = Jenkins.getInstance() def jobName = "yourJobName" String versionType = "minor" def job = jenkins.getItem(jobName) //get the current version parameter and update its default value paramsDef = job.getProperty(ParametersDefinitionProperty.class) if (paramsDef) { paramsDef.parameterDefinitions.each{ if("version".equals(it.name)){ println "Current version is ${it.defaultValue}" it.defaultValue = getUpdatedVersion(versionType, it.defaultValue) println "Next version is ${it.defaultValue}" } } } //determine the next version by the required type //and incrementing the current version def getUpdatedVersion(String versionType, String currentVersion){ def split = currentVersion.split('\\.') switch (versionType){ case "minor.minor": split[2]=++Integer.parseInt(split[2]) break case "minor": split[1]=++Integer.parseInt(split[1]) break; case "major": split[0]=++Integer.parseInt(split[0]) break; } return split.join('.') }