Open Ranjithsyncfusion opened 1 month ago
Same here!
- task: PublishToAzureServiceBus@2
inputs:
azureSubscription: myconnectionstring
serviceBusQueueName: myqueue
serviceBusNamespace: mynamespace
messageBody: |
{
"eventType":"Something.Something"
}
signPayload: false
waitForCompletion: true
useDataContractSerializer: true
Getting this error:
Job deployPolicyJob: Step references task 'PublishToAzureServiceBus' at version '2.241.1' which is not valid for the given job target.
Any fixes/workarrounds?
Hi Rob,
Still, I can't Resolve this issue, Please let me know if you have any solution.
I've created a workaround by simply leveraging a WebRequest with Azure Powershell.
- task: AzurePowerShell@5
name: notifyservicebus
displayName: Notify ServiceBus
inputs:
azureSubscription: $(MyServiceConnectionWithServiceBusDataSenderRoleOnServiceBus)
pwsh: true
azurePowerShellVersion: LatestVersion
ScriptType: "InlineScript"
Inline: |
# Create the body as a JSON string
$data = @{
"operationName" = "My/Event/type"
}
$body = @{
"data" = $data
} | ConvertTo-Json
# Get the access token
$accessToken = Get-AzAccessToken -ResourceUrl "$(MyServiceBusUrl)"
$token = $accessToken.Token
# Prepare headers
$headers = @{
Authorization = "Bearer $token"
'Content-Type' = 'application/json'
}
# URI for the request
$uri = "$(MyServiceBusUrl)$(MyQueueName)/messages?timeout=60"
# Send the request
$result = Invoke-WebRequest -Uri $uri -Headers $headers -Method Post -Body $body
$result
Let me know if this solves your issue :).
PS. This is NOT a serverless action. So you need to run this on an (selfhosted/microsoft hosted) agent :)
I also created the workaround using Python script It resolves my issue, please find the below code snippet.
script: | python -m pip install --upgrade pip pip install azure-identity azure-servicebus displayName: 'Install dependencies'
task: PythonScript@0 inputs: scriptSource: 'inline' script: | from azure.servicebus import ServiceBusClient from azure.servicebus import ServiceBusMessage
connection_str = "
def send_message_to_queue (connection_str, queue_name): servicebus_client = ServiceBusClient.from_connection_string(conn_str=connection_str) sender = servicebus_client.get_queue_sender(queue_name=queue_name) message = ServiceBusMessage("Hello world 002") sender.send_messages (message) sender.close() servicebus_client.close()
return "Message sent successfully"
if name == 'main': result = send_message_to_queue(connection_str, queue_name) print(result) Let me know if this is working for you
Task name
PublishToAzureServiceBus@2
Task version
2.241.1
Environment type (Please select at least one enviroment where you face this issue)
Azure DevOps Server type
Azure DevOps Server (Please specify exact version in the textbox below)
Azure DevOps Server Version (if applicable)
No response
Operation system
Ubuntu-lates and windows-latest
Question