Upravit

Sdílet prostřednictvím


PublishToAzureServiceBus@2 - Publish To Azure Service Bus v2 task

Sends a message to Azure Service Bus using a service connection (no agent is required).

This version of the task supports Entra ID and Workload identity federation through its Azure Resource Manager service connection input (azureSubscription). For more information, see the following Remarks section.

Syntax

# Publish To Azure Service Bus v2
# Sends a message to Azure Service Bus using an Azure Resource Manager service connection (no agent is required).
- task: PublishToAzureServiceBus@2
  inputs:
    azureSubscription: # string. Alias: connectedServiceName. Required. Azure Resource Manager service connection. 
    serviceBusQueueName: # string. Required. Azure Service Bus Queue name. 
    serviceBusNamespace: # string. Required. Azure Service Bus Namespace. 
    #messageBody: # string. Message body. 
    #waitForCompletion: false # boolean. Wait for task completion. Default: false.
    #useDataContractSerializer: true # boolean. Use .NET data contract serializer. Default: true.
  # Advanced
    #sessionId: # string. Session Id. 
    #signPayload: false # boolean. Sign the Message. Default: false.
    #certificateString: # string. Required when signPayload = true. Certificate Variable. 
    #signatureKey: 'signature' # string. Optional. Use when signPayload = true. Signature Property Key. Default: signature.

Inputs

azureSubscription - Azure Resource Manager service connection
Input alias: connectedServiceName. string. Required.

Specifies an Azure Resource Manager service connection.


serviceBusQueueName - Azure Service Bus Queue name
string. Required.

Specify the name of the queue for which the message is intended.


serviceBusNamespace - Azure Service Bus Namespace
string. Required.

Specify the namespace of your Azure Service Bus.


messageBody - Message body
string.

Specifies the JSON messageBody.


sessionId - Session Id
string.

Specifies the session ID with which the message is published. For session-based queues, the publishing fails if a value is not specified. For non session-based queues, a value does not need to be specified.


signPayload - Sign the Message
boolean. Default value: false.

If set to true, a private certificate will be added to the message.


certificateString - Certificate Variable
string. Required when signPayload = true.

Specifies the secret variable that contains the certificate content. This can also be a certificate stored in an Azure key vault that is linked to a variable group used by the release pipeline.


signatureKey - Signature Property Key
string. Optional. Use when signPayload = true. Default value: signature.

In Message Properties, specifies the key where the signature is. If left empty, the default value is signature.


waitForCompletion - Wait for task completion
boolean. Default value: false.

If set to true, this task will wait for the TaskCompleted event for the specified task timeout.


useDataContractSerializer - Use .NET data contract serializer
boolean. Default value: true.

Set useDataContractSerializer to false if you want to pass your message as a stream instead of an object.


Task control options

All tasks have control options in addition to their task inputs. For more information, see Control options and common task properties.

Output variables

None.

Remarks

Use this task in an agentless job of a release pipeline to send a message to an Azure Service Bus using a service connection (without using an agent).

Note

Can only be used in an agentless job of a release pipeline.

Access Azure Service Bus from Pipelines using Entra ID authentication

You can now use Entra ID authentication to access Azure Service Bus from Azure Pipelines. This allows you to take advantage of Workload identity federation to remove secrets management and Azure RBAC for fine grained access control.

Identities accessing Azure Service Bus will need to be granted one of the Azure built-in roles for Azure Service Bus on the Service Bus accessed.

The PublishToAzureServiceBus@2 task can be configured using an Azure Resource Manager service connection. Create an Azure Resource Manager service connection and populate the serviceBusQueueName and serviceBusNamespace properties of the task:

- task: PublishToAzureServiceBus@2
  inputs:
    azureSubscription: my-azure-service-connection
    serviceBusQueueName: my-service-bus-queue
    serviceBusNamespace: my-service-bus-namespace
    useDataContractSerializer: false
    messageBody: |
      {
        "property": "value"
      }

Where should a task signal completion?

To signal completion, the external service should POST completion data to the following pipelines REST endpoint.

{planUri}/{projectId}/_apis/distributedtask/hubs/{hubName}/plans/{planId}/events?api-version=2.0-preview.1

**Request Body**
 { "name": "TaskCompleted", "taskId": "taskInstanceId", "jobId": "jobId", "result": "succeeded" }

See this simple cmdline application for specifics.

In addition, a C# helper library is available to enable live logging and managing the task status for agentless tasks. Learn more about Async HTTP agentless tasks.

Requirements

Requirement Description
Pipeline types YAML, Classic build, Classic release
Runs on Server
Demands None
Capabilities This task does not satisfy any demands for subsequent tasks in the job.
Command restrictions Any
Settable variables Any
Agent version All supported agent versions.
Task category Utility