Azure / pipelines

Enable GitHub developers to trigger Azure Pipelines from a GitHub Actions workflow
MIT License
73 stars 83 forks source link

Release pipeline is not getting triggered when triggering the build pipeline using GitHub Actions #41

Closed ghostdevhv closed 2 years ago

ghostdevhv commented 2 years ago

On a relevant change, we run a GitHub action which then trigger the azure build pipeline. We have configured the pre-deployment condition that whenever there is a build from main branch it should trigger the release pipeline. In our case, it is not getting triggered. But if we manually run the build pipeline, the whole flow is working fine.

We did some debugging on our end and found out that, while firing the azure pipeline API, Actions is passing a random value "943" as a build reason in API body. It should pass one of the build reasons mentioned here.

With "943" as build reason, we are getting the below error:

System.Runtime.Serialization.SerializationException: Enum value '943' is invalid for type 'Microsoft.TeamFoundation.Build.WebApi.BuildReason' and cannot be serialized. Ensure that the necessary enum values are present and are marked with EnumMemberAttribute attribute if the type has DataContractAttribute attribute. at System.Runtime.Serialization.EnumDataContract.WriteEnumValue(XmlWriterDelegator writer, Object value) at System.Runtime.Serialization.XmlObjectSerializerWriteContext.WriteDataContractValue(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle declaredTypeHandle) at System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeWithoutXsiType(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle declaredTypeHandle) at System.Runtime.Serialization.XmlObjectSerializerWriteContext.InternalSerialize(XmlWriterDelegator xmlWriter, Object obj, Boolean isDeclaredType, Boolean writeXsiType, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle) at WriteBuildToXml(XmlWriterDelegator , Object , XmlObjectSerializerWriteContext , ClassDataContract ) at System.Runtime.Serialization.ClassDataContract.WriteXmlValue(XmlWriterDelegator xmlWriter, Object obj, XmlObjectSerializerWriteContext context) at System.Runtime.Serialization.XmlObjectSerializerWriteContext.WriteDataContractValue(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle declaredTypeHandle) at System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeWithoutXsiType(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle declaredTypeHandle) at System.Runtime.Serialization.XmlObjectSerializerWriteContext.InternalSerialize(XmlWriterDelegator xmlWriter, Object obj, Boolean isDeclaredType, Boolean writeXsiType, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle) at System.Runtime.Serialization.XmlObjectSerializerWriteContext.InternalSerializeReference(XmlWriterDelegator xmlWriter, Object obj, Boolean isDeclaredType, Boolean writeXsiType, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle) at WriteBuildCompletedEventToXml(XmlWriterDelegator , Object , XmlObjectSerializerWriteContext , ClassDataContract ) at System.Runtime.Serialization.ClassDataContract.WriteXmlValue(XmlWriterDelegator xmlWriter, Object obj, XmlObjectSerializerWriteContext context) at System.Runtime.Serialization.XmlObjectSerializerWriteContext.WriteDataContractValue(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle declaredTypeHandle) at System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeAndVerifyType(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, Boolean verifyKnownType, RuntimeTypeHandle declaredTypeHandle, Type declaredType) at System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeWithXsiType(XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle objectTypeHandle, Type objectType, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle, Type declaredType) at System.Runtime.Serialization.XmlObjectSerializerWriteContext.InternalSerialize(XmlWriterDelegator xmlWriter, Object obj, Boolean isDeclaredType, Boolean writeXsiType, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle) at System.Runtime.Serialization.XmlObjectSerializerWriteContext.InternalSerializeReference(XmlWriterDelegator xmlWriter, Object obj, Boolean isDeclaredType, Boolean writeXsiType, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle) at WriteServiceEventToXml(XmlWriterDelegator , Object , XmlObjectSerializerWriteContext , ClassDataContract ) at System.Runtime.Serialization.ClassDataContract.WriteXmlValue(XmlWriterDelegator xmlWriter, Object obj, XmlObjectSerializerWriteContext context) at System.Runtime.Serialization.XmlObjectSerializerWriteContext.WriteDataContractValue(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle declaredTypeHandle) at System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeWithoutXsiType(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle declaredTypeHandle) at System.Runtime.Serialization.DataContractSerializer.InternalWriteObjectContent(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver) at System.Runtime.Serialization.DataContractSerializer.InternalWriteObject(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver) at System.Runtime.Serialization.XmlObjectSerializer.WriteObjectHandleExceptions(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver) at System.Runtime.Serialization.XmlObjectSerializer.WriteObject(XmlDictionaryWriter writer, Object graph) at System.Runtime.Serialization.XmlObjectSerializer.WriteObject(Stream stream, Object graph) at Microsoft.ServiceBus.Messaging.BrokeredMessage..ctor(Object serializableObject, XmlObjectSerializer serializer) at Microsoft.VisualStudio.Services.Cloud.ServiceBusPublishHelper.GetBrokeredMessage(MessageBusMessage input, String messageBusIdentifier) in D:\v2.0\P1\_work\5\s\Vssf\Sdk\CloudServer\ServiceBus\ServiceBusPublishHelper.cs:line 54 at Microsoft.VisualStudio.Services.Cloud.ServiceBusPublishHighAvailabilityConnection.PublishMessagesInternal(IVssRequestContext requestContext, String messageBusIdentifier, MessageBusMessage[] messagesToPublish, List 1 messages, Boolean publishToSecondary) in D:\v2.0\P1\_work\5\s\Vssf\Sdk\CloudServer\ServiceBus\ServiceBusPublishHighAvailabilityConnection.cs:line 165 at Microsoft.VisualStudio.Services.Cloud.ServiceBusPublishHighAvailabilityConnection.PublishHelper(IVssRequestContext requestContext, String messageBusIdentifier, MessageBusMessage[] messagesToPublish, Boolean publishToSecondary) in D:\v2.0\P1\_work\5\s\Vssf\Sdk\CloudServer\ServiceBus\ServiceBusPublishHighAvailabilityConnection.cs:line 141

We created a test pipeline and fired the build API using "triggered" as build reason and our whole pipeline is working fine.

Possible Solution: Instead of just passing a random value as build reason, pass a valid reason string as mentioned in this doc.

ghostdevhv commented 2 years ago

The reason we are getting 943 is that this action is not using the latest azure-devops-node-api version. Enum value for "triggered" got changed in this PR - https://github.com/microsoft/azure-devops-node-api/pull/368/files?file-filters%5B%5D=.json&file-filters%5B%5D=.ts#diff-2400cd68b4f3536f59bb07ee7f99a260ce1cd558d0bfe051d6f2c8f9fa9519b8L1129. We should update this action to use the latest version to avoid such misunderstandings.

Since the triggered value is 943, we are passing this value here to the azure pipeline API and that is causing the issue to trigger the release pipeline. Instead of passing BuildInterfaces.BuildReason.Triggered as reason, we can just pass "triggered" to resolve this issue.