[英]Compare two versions in logic apps
我有两个版本字符串,我需要像 .NET Version
类型那样比较它们(知道主要版本、次要版本,而不仅仅是字符串)以查看哪个更新。 我的问题是:如何检查逻辑应用程序中哪个版本字符串较新?
有没有比字符串操作的“蛮力”方法更好的方法?
major = split(variables('CurrentImageVer', '.'))[0]
minor = split(variables('CurrentImageVer', '.'))[1]
等等...
我同意@Skin,因为版本本身是字符串类型,这可以通过字符串操作来完成。 以下是从我这边复制后对我有用的东西。
出于演示目的,我在数组变量中使用了以下 2 个版本。
[
"1.2.31",
"1.2.30"
]
首先,我试图从数组中拆分两个版本。
然后我使用条件连接器检查版本 1 是否大于另一个。
结果:
下面是我的逻辑应用程序的完整 JSON。
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Compose": {
"inputs": "@variables('Latest Version')",
"runAfter": {
"Until": [
"Succeeded"
]
},
"type": "Compose"
},
"Flag": {
"inputs": {
"variables": [
{
"name": "Flag",
"type": "integer",
"value": 0
}
]
},
"runAfter": {
"Initialize_variable": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Initialize_variable": {
"inputs": {
"variables": [
{
"name": "Versions",
"type": "array",
"value": [
"1.2.31",
"1.2.30"
]
}
]
},
"runAfter": {},
"type": "InitializeVariable"
},
"Latest_Version": {
"inputs": {
"variables": [
{
"name": "Latest Version",
"type": "string",
"value": "Latest Not Found"
}
]
},
"runAfter": {
"Initialize_variable": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Split_Version1": {
"inputs": "@split(variables('Versions')[0],'.')",
"runAfter": {
"Latest_Version": [
"Succeeded"
]
},
"type": "Compose"
},
"Split_Version2": {
"inputs": "@split(variables('Versions')[1],'.')",
"runAfter": {
"Flag": [
"Succeeded"
]
},
"type": "Compose"
},
"Until": {
"actions": {
"Condition": {
"actions": {
"Set_variable_2": {
"inputs": {
"name": "Latest Version",
"value": "@{variables('Versions')[0]} is the latest version"
},
"runAfter": {},
"type": "SetVariable"
}
},
"else": {
"actions": {
"Condition_2": {
"actions": {
"Set_variable": {
"inputs": {
"name": "Latest Version",
"value": "@{variables('Versions')[1]} is the latest version"
},
"runAfter": {},
"type": "SetVariable"
}
},
"expression": {
"and": [
{
"less": [
"@outputs('Split_Version1')[variables('Flag')]",
"@outputs('Split_Version2')[variables('Flag')]"
]
},
{
"equals": [
"@variables('Latest Version')",
"Latest Not Found"
]
}
]
},
"runAfter": {},
"type": "If"
}
}
},
"expression": {
"and": [
{
"greater": [
"@outputs('Split_Version1')[variables('Flag')]",
"@outputs('Split_Version2')[variables('Flag')]"
]
},
{
"equals": [
"@variables('Latest Version')",
"Latest Not Found"
]
}
]
},
"runAfter": {},
"type": "If"
},
"Increment_variable": {
"inputs": {
"name": "Flag",
"value": 1
},
"runAfter": {
"Condition": [
"Succeeded"
]
},
"type": "IncrementVariable"
}
},
"expression": "@equals(variables('Flag'), length(outputs('Split_Version1')))",
"limit": {
"count": 60,
"timeout": "PT1H"
},
"runAfter": {
"Split_Version1": [
"Succeeded"
],
"Split_Version2": [
"Succeeded"
]
},
"type": "Until"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"triggers": {
"manual": {
"inputs": {
"schema": {}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.