microsoft / azure-pipelines-tasks

Tasks for Azure Pipelines
https://aka.ms/tfbuild
MIT License
3.47k stars 2.6k forks source link

Facing the version not valid issue in azure pipeline. #20172

Open Ranjithsyncfusion opened 1 month ago

Ranjithsyncfusion commented 1 month ago

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

Why I am facing the below issue while try to sent a custom messages form Azure DevOps pipeline to Azure Bus Service Queue.

issue: Job ExampleJob: Step references task 'PublishToAzureServiceBus' at version '2.241.1' which is not valid for the given job target.
RobHofmann commented 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?

Ranjithsyncfusion commented 1 month ago

Hi Rob,

Still, I can't Resolve this issue, Please let me know if you have any solution.

RobHofmann commented 1 month ago

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 :)

Ranjithsyncfusion commented 1 month ago

I also created the workaround using Python script It resolves my issue, please find the below code snippet.