Reputation: 53
I have a a logic app that goes out and does an http GET on a website. It then uses a condition to check if that webpage has a .tar file and that the version of that software matches. For example: if the website has a .tar file with the integer "29" it then generates an email to me to approve for an update. If I approve I have it set to update the variable to the next version by an increment of 1. The idea is that it will run this occurrence weekly and because my version variable is always updated after I approve, my condition will reflect that every time if checks.
My problem is that after the variable is updated it does not reflect so on the next occurrence. I'm trying to figure out what kind of control I need in place to maintain this loop and variable state without it defaulting back to the first variable value that I've declared.
Upvotes: 1
Views: 685
Reputation: 8244
Thank you @Skin for pointing in the right direction. As mentioned, currently there is no way you can built-in way to do this. Rather you can read and save the value to storage. Below is a sample that worked for me. I am using blob storage to read and save the value for the variable.
Firstly, I have initialized a version named variable. Using Get blob content
action I'm reading the value of version and setting the same value to the version variable.
In the next step I'm using condition
action checking for the conditions and incrementing the version variable if the resultant is true and storing the same value to the same blob in blob storage.
Initial value in my blob
Results of version variable after 1st Run:
Results of version variable after 2nd Run:
To reproduce the same in your logic you can use the below code view.
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Compose": {
"inputs": "29 and .tar",
"runAfter": {},
"type": "Compose"
},
"Condition": {
"actions": {
"Increment_variable": {
"inputs": {
"name": "version",
"value": 1
},
"runAfter": {},
"type": "IncrementVariable"
},
"Update_blob_(V2)": {
"inputs": {
"body": "@variables('version')",
"headers": {
"ReadFileMetadataFromServer": true
},
"host": {
"connection": {
"name": "@parameters('$connections')['azureblob']['connectionId']"
}
},
"method": "put",
"path": "<PATH>"
},
"metadata": {
"JTJmY29udGFpbmVyMSUyZnZlcnNpb24udHh0": "/container1/version.txt"
},
"runAfter": {
"Increment_variable": [
"Succeeded"
]
},
"type": "ApiConnection"
}
},
"expression": {
"and": [
{
"contains": [
"@outputs('Compose')",
"@string('.tar')"
]
},
{
"contains": [
"@outputs('Compose')",
"@string('29')"
]
}
]
},
"runAfter": {
"Set_variable": [
"Succeeded"
]
},
"type": "If"
},
"Get_blob_content_(V2)": {
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['azureblob']['connectionId']"
}
},
"method": "get",
"path": "<PATH>",
"queries": {
"inferContentType": true
}
},
"metadata": {
"JTJmY29udGFpbmVyMSUyZnZlcnNpb24udHh0": "/container1/version.txt"
},
"runAfter": {
"Initialize_variable": [
"Succeeded"
]
},
"type": "ApiConnection"
},
"Initialize_variable": {
"inputs": {
"variables": [
{
"name": "version",
"type": "integer"
}
]
},
"runAfter": {
"Compose": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Set_variable": {
"inputs": {
"name": "version",
"value": "@int(body('Get_blob_content_(V2)'))"
},
"runAfter": {
"Get_blob_content_(V2)": [
"Succeeded"
]
},
"type": "SetVariable"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
},
"Sample": {
"defaultValue": "@outputs('Compose')",
"type": "String"
}
},
"triggers": {
"manual": {
"inputs": {},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {
"$connections": {
"value": {
"azureblob": {
"connectionId": "/subscriptions/<SUB-ID>/resourceGroups/<RG>/providers/Microsoft.Web/connections/azureblob",
"connectionName": "azureblob",
"id": "/subscriptions/<SUB-ID>/providers/Microsoft.Web/locations/centralus/managedApis/azureblob"
}
}
}
}
}
Upvotes: 2