예제 #1
0
        static async Task ModifyJenkinsProjectAsync(
            HttpClient httpClient,
            string projectName,
            XmlDocument projectDescriptor,
            List <string> pendingParametersToConfigure,
            bool bXmlVersionChanged)
        {
            string modifiedXmlProject = Path.GetTempFileName();

            try
            {
                ProjectDescriptor.AddMissingParameters(
                    projectDescriptor,
                    pendingParametersToConfigure,
                    modifiedXmlProject);

                string payLoadStr = File.ReadAllText(modifiedXmlProject);
                if (bXmlVersionChanged)
                {
                    payLoadStr = ProjectXmlVersionFix.RestoreToV1_1(payLoadStr);
                }

                var payLoad = new StringContent(
                    payLoadStr,
                    System.Text.Encoding.UTF8,
                    "application/xml");

                string endPoint = string.Format(GET_JOB_CONFIG_URI, projectName);
                HttpResponseMessage response = await PostWithRetriesAsync(httpClient, endPoint, payLoad);

                if (response.IsSuccessStatusCode)
                {
                    return;
                }

                throw new InvalidOperationException(string.Format(
                                                        "Unable to update config.xml file for project [{0}] " +
                                                        "in order to setup required build parameters: {1}",
                                                        projectName, response.ReasonPhrase));
            }
            finally
            {
                if (File.Exists(modifiedXmlProject))
                {
                    File.Delete(modifiedXmlProject);
                }
            }
        }
예제 #2
0
        internal static async Task <string> QueueBuildAsync(
            string projectName,
            string plasticUpdateToSpec,
            string buildComment,
            Dictionary <string, string> botRequestProperties,
            HttpClient httpClient)
        {
            XmlDocument projectDescriptor  = null;
            bool        bXmlVersionChanged = false;

            string projectDescriptorContents = await GetProjectDescriptorAsync(projectName, httpClient);

            projectDescriptorContents = ProjectXmlVersionFix.EnsureV1_0(
                projectDescriptorContents, out bXmlVersionChanged);

            projectDescriptor = ProjectDescriptor.Parse(projectDescriptorContents);

            List <BuildProperty> requestProperties = QueueBuildRequestProps.Create(plasticUpdateToSpec, botRequestProperties);
            string projectAuthToken = string.Empty;

            projectAuthToken = ProjectDescriptor.GetAuthToken(projectDescriptor);

            List <string> pendingParametersToConfigure =
                ProjectDescriptor.GetMissingParameters(projectDescriptor, requestProperties);

            if (pendingParametersToConfigure.Count > 0)
            {
                await ModifyJenkinsProjectAsync(
                    httpClient,
                    projectName,
                    projectDescriptor,
                    pendingParametersToConfigure,
                    bXmlVersionChanged);
            }

            if (!string.IsNullOrEmpty(projectAuthToken))
            {
                requestProperties.Add(new BuildProperty("token", projectAuthToken));
            }

            if (!string.IsNullOrEmpty(buildComment))
            {
                requestProperties.Add(new BuildProperty("cause", buildComment));
            }

            string endPoint = Uri.EscapeUriString(
                string.Format(
                    QUEUE_BUILD_URI_FORMAT,
                    projectName,
                    BuildPropertiesUri(requestProperties)));

            HttpResponseMessage response = await PostWithRetriesAsync(httpClient, endPoint, null);

            if (!response.IsSuccessStatusCode)
            {
                return(string.Empty);
            }

            if (response.Headers.Location != null)
            {
                return(GetBuildNumberFromLocationPathHeader(
                           response.Headers.Location.AbsolutePath));
            }

            return(string.Empty);
        }