<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright 2020 ThoughtWorks, Inc.
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~     http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->
<xsd:schema elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:annotation>
        <xsd:documentation xml:lang="en">
            Configuration schema for Cruise. Copyright (c) 2009 ThoughtWorks, Inc.
            www.thoughtworks.com. All rights reserved.
        </xsd:documentation>
    </xsd:annotation>
    <xsd:element name="cruise">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element minOccurs="0" maxOccurs="1" name="server">
                    <xsd:complexType>
                        <xsd:all>
                            <xsd:element minOccurs="0" maxOccurs="1" name="license">
                                <xsd:complexType>
                                    <xsd:simpleContent>
                                        <xsd:extension base="xsd:string">
                                            <xsd:attribute name="user" type="xsd:string"/>
                                        </xsd:extension>
                                    </xsd:simpleContent>
                                </xsd:complexType>
                            </xsd:element>
                            <xsd:element minOccurs="0" maxOccurs="1" name="security" type="securityType"/>
                            <xsd:element minOccurs="0" maxOccurs="1" name="mailhost" type="mailHostType"/>
                            <xsd:element minOccurs="0" maxOccurs="1" name="known-servers" type="knownServersType"/>
                        </xsd:all>
                        <xsd:attributeGroup ref="serverAttributeGroup"/>
                    </xsd:complexType>
                </xsd:element>
                <xsd:element minOccurs="0" maxOccurs="unbounded" name="pipelines" type="pipelinesType"/>
                <xsd:element minOccurs="0" maxOccurs="1" name="templates" type="templatesType">
                    <xsd:unique name="uniquePipelineTemplateName">
                        <xsd:selector xpath="pipeline"/>
                        <xsd:field xpath="@name"/>
                    </xsd:unique>
                </xsd:element>
                <xsd:element minOccurs="0" maxOccurs="1" name="environments" type="environmentsType">
                    <xsd:unique name="uniqueEnvironmentName">
                        <xsd:selector xpath="environment"/>
                        <xsd:field xpath="@name"/>
                    </xsd:unique>
                    <xsd:unique name="uniqueEnvironmentPipelineName">
                        <xsd:selector xpath=".//environment/pipelines/pipeline"/>
                        <xsd:field xpath="@name"/>
                    </xsd:unique>
                </xsd:element>
                <xsd:element minOccurs="0" name="agents" type="agentsType">
                    <xsd:unique name="uniqueUuid">
                        <xsd:selector xpath="agent"/>
                        <xsd:field xpath="@uuid"/>
                    </xsd:unique>
                </xsd:element>
                <xsd:element minOccurs="0" name="vmms" type="vmmsType"/>
            </xsd:sequence>
            <xsd:attribute name="schemaVersion" type="xsd:int" use="required" fixed="47"/>
        </xsd:complexType>
        <xsd:unique name="uniquePipelines">
            <xsd:selector xpath="pipelines"/>
            <xsd:field xpath="@group"/>
        </xsd:unique>
        <xsd:unique name="uniqueServerAlias">
            <xsd:selector xpath=".//cruise/server/known-servers/server"/>
            <xsd:field xpath="@alias"/>
        </xsd:unique>
    </xsd:element>
    <xsd:complexType name="knownServersType">
        <xsd:sequence>
            <xsd:element minOccurs="0" maxOccurs="unbounded" name="server" type="knownServerType"/>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="knownServerType">
        <xsd:attribute name="host" type="xsd:string" use="required"/>
        <xsd:attribute name="username" type="xsd:string" use="optional"/>
        <xsd:attribute name="password" type="xsd:string" use="optional"/>
        <xsd:attribute name="port" type="xsd:integer" use="required"/>
        <xsd:attribute name="sslPort" type="xsd:integer" use="required"/>
        <xsd:attribute name="alias" type="xsd:string" use="required"/>
    </xsd:complexType>
    <xsd:complexType name="securityType">
        <xsd:all>
            <xsd:element minOccurs="0" maxOccurs="1" name="luau" type="luauType" />
            <xsd:element minOccurs="0" maxOccurs="1" name="ldap" type="ldapType"/>
            <xsd:element minOccurs="0" maxOccurs="1" name="passwordFile" type="passwordfileType"/>
            <xsd:element minOccurs="0" maxOccurs="1" name="roles" type="rolesType">
                <xsd:unique name="uniqueRole">
                    <xsd:selector xpath="role"/>
                    <xsd:field xpath="@name"/>
                    <!-- Unique role name -->
                </xsd:unique>
            </xsd:element>
            <xsd:element minOccurs="0" maxOccurs="1" name="admins" type="adminType">
                <xsd:unique name="uniqueUserInAdmins">
                    <xsd:selector xpath="user"/>
                    <xsd:field xpath="."/>
                </xsd:unique>
                <xsd:unique name="uniqueRoleInAdmins">
                    <xsd:selector xpath="role"/>
                    <xsd:field xpath="."/>
                </xsd:unique>
            </xsd:element>
        </xsd:all>
        <xsd:attribute name="anonymous" type="xsd:boolean"/>
        <xsd:attribute name="allowOnlyKnownUsersToLogin" type="xsd:boolean"/>
    </xsd:complexType>
    <xsd:complexType name="mailHostType">
        <xsd:attribute name="hostname" type="xsd:string" use="required"/>
        <xsd:attribute name="port" type="xsd:integer" use="required"/>
        <xsd:attribute name="username" type="xsd:string"/>
        <xsd:attribute name="password" type="xsd:string"/>
        <xsd:attribute name="encryptedPassword" type="xsd:string"/>
        <xsd:attribute name="tls" type="xsd:boolean" use="required"/>
        <xsd:attribute name="from" type="emailType" use="required"/>
        <xsd:attribute name="admin" type="emailType" use="required"/>
    </xsd:complexType>
    <xsd:simpleType name="emailType">
        <xsd:restriction base="xsd:string">
            <xsd:pattern value=".*@.*"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:complexType name="rolesType">
        <xsd:sequence>
            <xsd:element minOccurs="1" maxOccurs="unbounded" name="role">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element minOccurs="0" maxOccurs="unbounded" name="user">
                            <xsd:simpleType>
                                <xsd:restriction base="xsd:string">
                                    <xsd:minLength value="1"/>
                                </xsd:restriction>
                            </xsd:simpleType>
                        </xsd:element>
                    </xsd:sequence>
                    <xsd:attribute name="name" type="nameType" use="required"/>
                </xsd:complexType>
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="adminType">
        <xsd:choice minOccurs="0" maxOccurs="unbounded">
            <xsd:element name="user" type="xsd:string"/>
            <xsd:element name="role" type="xsd:string"/>
        </xsd:choice>
    </xsd:complexType>
    <xsd:complexType name="vmmsType">
        <xsd:choice minOccurs="0" maxOccurs="unbounded">
            <xsd:element name="ec2" type="ec2Type"/>
        </xsd:choice>
    </xsd:complexType>
    <xsd:complexType name="ec2Type">
        <xsd:sequence>
            <xsd:element minOccurs="1" maxOccurs="unbounded" name="ami">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element minOccurs="0" name="resources" type="resourcesType"/>
                    </xsd:sequence>
                    <xsd:attribute name="imageId" type="xsd:string" use="required"/>
                </xsd:complexType>
            </xsd:element>
        </xsd:sequence>
        <xsd:attribute name="accessKey" type="xsd:string" use="required"/>
        <xsd:attribute name="secretAccessKey" type="xsd:string" use="required"/>
    </xsd:complexType>
    <xsd:complexType name="luauType">
        <xsd:attribute name="url" use="required">
            <xsd:simpleType>
                <xsd:restriction base="xsd:string">
                    <xsd:pattern value="https://.+"/>
                </xsd:restriction>
            </xsd:simpleType>
        </xsd:attribute>
        <xsd:attribute name="clientKey" type="xsd:string" use="required"/>
        <xsd:attribute name="authState" type="xsd:string" use="required"/>
    </xsd:complexType>
    <xsd:complexType name="ldapType">
        <xsd:attribute name="uri" type="xsd:string" use="required"/>
        <xsd:attribute name="managerDn" type="xsd:string"/>
        <xsd:attribute name="managerPassword" type="xsd:string"/>
        <xsd:attribute name="encryptedManagerPassword" type="xsd:string"/>
        <xsd:attribute name="searchBase" type="xsd:string" use="required"/>
        <xsd:attribute name="searchFilter" type="xsd:string"/>
    </xsd:complexType>
    <xsd:complexType name="passwordfileType">
        <xsd:attribute name="path" type="xsd:string" use="required"/>
    </xsd:complexType>
    <xsd:complexType name="pipelinesType">
        <xsd:sequence>
            <xsd:element minOccurs="0" maxOccurs="1" name="authorization" type="authorizationType"/>
            <xsd:element minOccurs="0" maxOccurs="unbounded" name="pipeline">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element minOccurs="0" maxOccurs="1" ref="params"/>
                        <xsd:choice minOccurs="0" maxOccurs="1">
                            <xsd:element name="trackingtool" type="trackingToolType"/>
                            <xsd:element name="mingle" type="mingleType"/>
                        </xsd:choice>
                        <xsd:element minOccurs="0" maxOccurs="1" name="timer" type="timerType"/>
                        <xsd:element minOccurs="0" maxOccurs="1" ref="environmentvariables"/>
                        <xsd:element minOccurs="0" maxOccurs="unbounded" name="dependencies" type="dependenciesType"/>
                        <xsd:element name="materials" type="materialsType">
                            <xsd:unique name="uniqueDependencyMaterial">
                                <xsd:selector xpath="pipeline"/>
                                <xsd:field xpath="@pipelineName"/>
                                <xsd:field xpath="@stageName"/>
                            </xsd:unique>
                        </xsd:element>
                        <xsd:element minOccurs="0" maxOccurs="unbounded" name="stage" type="stageType"/>
                    </xsd:sequence>
                    <xsd:attribute name="name" type="nameType" use="required"/>
                    <xsd:attribute name="labeltemplate" type="labelType"/>
                    <xsd:attribute name="isLocked" type="xsd:boolean"/>
                    <xsd:attribute name="template" type="nameType" use="optional"/>
                </xsd:complexType>
            </xsd:element>
        </xsd:sequence>
        <xsd:attribute name="group" use="optional" default="defaultGroup" type="nameType"/>
    </xsd:complexType>
    <xsd:complexType name="stageType">
        <xsd:sequence>
            <xsd:element minOccurs="0" maxOccurs="1" name="approval" type="approvalType"/>
            <xsd:element minOccurs="0" maxOccurs="1" ref="environmentvariables"/>
            <xsd:element maxOccurs="unbounded" name="jobs" type="jobsType">
                <xsd:unique name="uniqueJob">
                    <xsd:selector xpath="job"/>
                    <xsd:field xpath="@name"/>
                </xsd:unique>
            </xsd:element>
        </xsd:sequence>
        <xsd:attribute name="name" type="nameType" use="required"/>
        <xsd:attribute name="fetchMaterials" type="xsd:boolean"/>
        <xsd:attribute name="cleanWorkingDir" type="xsd:boolean"/>
        <xsd:attribute name="artifactCleanupProhibited" type="xsd:boolean"/>
    </xsd:complexType>
    <xsd:complexType name="approvalType">
        <xsd:sequence>
            <xsd:element minOccurs="0" maxOccurs="1" name="authorization" type="authorizedUserListType"/>
        </xsd:sequence>
        <xsd:attribute name="type" use="required">
            <xsd:simpleType>
                <xsd:restriction base="xsd:string">
                    <xsd:enumeration value="success"/>
                    <xsd:enumeration value="manual"/>
                </xsd:restriction>
            </xsd:simpleType>
        </xsd:attribute>
    </xsd:complexType>
    <xsd:complexType name="materialsType">
        <xsd:choice minOccurs="1" maxOccurs="unbounded">
            <xsd:element name="pipeline" type="pipelineType"/>
            <xsd:element name="svn" type="svnType"/>
            <xsd:element name="hg" type="hgType"/>
            <xsd:element name="p4" type="p4Type"/>
            <xsd:element name="git" type="gitType"/>
            <xsd:element name="tfs" type="tfsType"/>
        </xsd:choice>

    </xsd:complexType>
    <xsd:complexType name="pipelineType">
        <xsd:attribute name="pipelineName" type="xsd:string" use="required"/>
        <xsd:attribute name="stageName" type="xsd:string" use="required"/>
        <xsd:attribute name="materialName" type="nameType" use="optional"/>
        <xsd:attribute name="serverAlias" type="xsd:string" use="optional"/>
    </xsd:complexType>
    <xsd:complexType name="svnType">
        <xsd:sequence>
            <xsd:element name="filter" type="filterType" minOccurs="0" maxOccurs="1"/>
        </xsd:sequence>
        <xsd:attribute name="url" type="xsd:string" use="required"/>
        <xsd:attribute name="username" type="xsd:string"/>
        <xsd:attribute name="password" type="xsd:string"/>
        <xsd:attribute name="encryptedPassword" type="xsd:string" />
        <xsd:attribute name="checkexternals" type="xsd:boolean"/>
        <xsd:attribute name="dest" type="filePathType" use="optional"/>
        <xsd:attribute name="materialName" type="nameType" use="optional"/>
        <xsd:attribute name="autoUpdate" type="xsd:boolean" use="optional"/>
    </xsd:complexType>
    <xsd:complexType name="p4Type">
        <xsd:sequence>
            <xsd:element name="view" minOccurs="1" maxOccurs="1"/>
            <xsd:element name="filter" type="filterType" minOccurs="0" maxOccurs="1"/>
        </xsd:sequence>
        <xsd:attribute name="port" type="xsd:string" use="required"/>
        <xsd:attribute name="username" type="xsd:string"/>
        <xsd:attribute name="password" type="xsd:string"/>
        <xsd:attribute name="encryptedPassword" type="xsd:string"/>
        <xsd:attribute name="useTickets" type="xsd:boolean" use="optional"/>
        <xsd:attribute name="dest" type="filePathType" use="optional"/>
        <xsd:attribute name="materialName" type="nameType" use="optional"/>
        <xsd:attribute name="autoUpdate" type="xsd:boolean" use="optional"/>
    </xsd:complexType>
    <xsd:complexType name="gitType">
        <xsd:sequence>
            <xsd:element name="filter" type="filterType" minOccurs="0" maxOccurs="1"/>
        </xsd:sequence>
        <xsd:attribute name="url" type="xsd:string" use="required"/>
        <xsd:attribute name="dest" type="filePathType" use="optional"/>
        <xsd:attribute name="branch" type="xsd:string" use="optional"/>
        <xsd:attribute name="materialName" type="nameType" use="optional"/>
        <xsd:attribute name="autoUpdate" type="xsd:boolean" use="optional"/>
    </xsd:complexType>
    <xsd:complexType name="hgType">
        <xsd:sequence>
            <xsd:element name="filter" type="filterType" minOccurs="0" maxOccurs="1"/>
        </xsd:sequence>
        <xsd:attribute name="url" type="xsd:string" use="required"/>
        <xsd:attribute name="dest" type="filePathType" use="optional"/>
        <xsd:attribute name="materialName" type="nameType" use="optional"/>
        <xsd:attribute name="autoUpdate" type="xsd:boolean" use="optional"/>
    </xsd:complexType>
    <xsd:complexType name="tfsType">
        <xsd:sequence>
            <xsd:element name="filter" type="filterType" minOccurs="0" maxOccurs="1"/>
        </xsd:sequence>
        <xsd:attribute name="url" type="xsd:string" use="required"/>
        <xsd:attribute name="username" type="xsd:string" use="required"/>
        <xsd:attribute name="password" type="xsd:string"/>
        <xsd:attribute name="encryptedPassword" type="xsd:string" />
        <xsd:attribute name="workspace" type="tfsWorkspaceType" use="required" />
        <xsd:attribute name="projectPath" type="xsd:string" use="required"/>
        <xsd:attribute name="workspaceOwner" type="xsd:string" use="required"/>
        <xsd:attribute name="dest" type="filePathType" use="optional"/>
        <xsd:attribute name="materialName" type="nameType" use="optional"/>
        <xsd:attribute name="autoUpdate" type="xsd:boolean" use="optional"/>
    </xsd:complexType>
    <xsd:complexType name="jobsType">
        <xsd:sequence>
            <xsd:element maxOccurs="unbounded" name="job" type="jobType"/>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="jobType">
        <xsd:all>
            <xsd:element ref="environmentvariables" minOccurs="0" maxOccurs="1"/>
            <xsd:element minOccurs="0" name="tasks" type="tasksType"/>
            <xsd:element minOccurs="0" name="artifacts" type="artifactsType"/>
            <xsd:element minOccurs="0" name="resources" type="resourcesType"/>
            <xsd:element minOccurs="0" name="tabs" type="tabsType">
                <xsd:unique name="uniqueTabsName">
                    <xsd:selector xpath="tab"/>
                    <xsd:field xpath="@name"/>
                </xsd:unique>
            </xsd:element>
            <xsd:element minOccurs="0" name="properties" type="propertiesType">
                <xsd:unique name="uniqueProperty">
                    <xsd:selector xpath="property"/>
                    <xsd:field xpath="@name"/>
                </xsd:unique>
            </xsd:element>
        </xsd:all>
        <xsd:attribute name="name" type="jobnameType" use="required"/>
        <xsd:attribute name="runOnAllAgents" type="xsd:boolean" use="optional" default="false"/>
        <xsd:attribute name="timeout" type="xsd:double" use="optional"/>
    </xsd:complexType>
    <xsd:complexType name="resourcesType">
        <xsd:sequence>
            <xsd:element minOccurs="0" maxOccurs="unbounded" name="resource" type="xsd:string"/>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="tabsType">
        <xsd:sequence>
            <xsd:element minOccurs="0" maxOccurs="unbounded" ref="tab"/>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:attributeGroup name="taskAttributes">
        <xsd:attribute name="workingdir" type="xsd:string" use="optional"/>
        <xsd:attribute name="buildfile" type="xsd:string" use="optional"/>
        <xsd:attribute name="target" type="xsd:string" use="optional"/>
    </xsd:attributeGroup>
    <xsd:complexType name="taskType" abstract="true">
    </xsd:complexType>
    <xsd:complexType name="antType">
        <xsd:complexContent mixed="false">
            <xsd:extension base="taskType">
                <xsd:choice minOccurs="0" maxOccurs="unbounded">
                    <xsd:element name="runif" type="runIfType"/>
                    <xsd:element name="oncancel" type="onCancelType"/>
                </xsd:choice>
                <xsd:attributeGroup ref="taskAttributes"/>
            </xsd:extension>
        </xsd:complexContent>
    </xsd:complexType>
    <xsd:complexType name="nantType">
        <xsd:complexContent mixed="false">
            <xsd:extension base="taskType">
                <xsd:choice minOccurs="0" maxOccurs="unbounded">
                    <xsd:element name="runif" type="runIfType"/>
                    <xsd:element name="oncancel" type="onCancelType"/>
                </xsd:choice>
                <xsd:attributeGroup ref="taskAttributes"/>
                <xsd:attribute name="nantpath" type="xsd:string" use="optional"/>
            </xsd:extension>
        </xsd:complexContent>
    </xsd:complexType>
    <xsd:complexType name="execType">
        <xsd:complexContent mixed="false">
            <xsd:extension base="taskType">
                <xsd:choice minOccurs="0" maxOccurs="unbounded">
                    <xsd:element name="runif" type="runIfType"/>
                    <xsd:element name="oncancel" type="onCancelType"/>
                    <xsd:element name="arg" type="xsd:string"/>
                </xsd:choice>
                <xsd:attributeGroup ref="execAttributes"/>
            </xsd:extension>
        </xsd:complexContent>
    </xsd:complexType>
    <xsd:complexType name="rakeType">
        <xsd:complexContent mixed="false">
            <xsd:extension base="taskType">
                <xsd:choice minOccurs="0" maxOccurs="unbounded">
                    <xsd:element name="runif" type="runIfType"/>
                    <xsd:element name="oncancel" type="onCancelType"/>
                </xsd:choice>
                <xsd:attributeGroup ref="taskAttributes"/>
            </xsd:extension>
        </xsd:complexContent>
    </xsd:complexType>
    <xsd:complexType name="fetchType">
        <xsd:complexContent mixed="false">
            <xsd:extension base="taskType">
                <xsd:choice minOccurs="0" maxOccurs="unbounded">
                    <xsd:element name="runif" type="runIfType"/>
                    <xsd:element name="oncancel" type="onCancelType"/>
                </xsd:choice>
                <xsd:attribute name="pipeline" type="xsd:string" use="optional"/>
                <xsd:attribute name="stage" type="xsd:string" use="required"/>
                <xsd:attribute name="job" type="xsd:string" use="required"/>
                <xsd:attribute name="srcdir" type="filePathType"/>
                <xsd:attribute name="srcfile" type="filePathType"/>
                <xsd:attribute name="dest" type="filePathType"/>
                <xsd:attribute name="serverAlias" type="xsd:string"/>
                <xsd:attributeGroup ref="taskAttributes"/>
            </xsd:extension>
        </xsd:complexContent>
    </xsd:complexType>

    <xsd:element abstract="true" name="task" type="taskType"/>
    <xsd:element name="ant" substitutionGroup="task" type="antType"/>
    <xsd:element name="nant" substitutionGroup="task" type="nantType"/>
    <xsd:element name="exec" substitutionGroup="task" type="execType"/>
    <xsd:element name="rake" substitutionGroup="task" type="rakeType"/>
    <xsd:element name="fetchartifact" substitutionGroup="task" type="fetchType"/>

    <xsd:complexType name="tasksType">
        <xsd:sequence>
            <xsd:element minOccurs="0" maxOccurs="unbounded" ref="task"/>
            <xsd:any minOccurs="0" maxOccurs="unbounded"/>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="artifactsType">
        <xsd:sequence>
            <xsd:element minOccurs="0" maxOccurs="unbounded" ref="artifactType"/>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="abstractArtifactType" abstract="true"/>
    <xsd:complexType name="logType">
        <xsd:complexContent mixed="false">
            <xsd:extension base="abstractArtifactType">
                <xsd:attributeGroup ref="genericArtifactAttributeGroup"/>
            </xsd:extension>
        </xsd:complexContent>
    </xsd:complexType>
    <xsd:complexType name="testType">
        <xsd:complexContent mixed="false">
            <xsd:extension base="abstractArtifactType">
                <xsd:attributeGroup ref="genericArtifactAttributeGroup"/>
            </xsd:extension>
        </xsd:complexContent>
    </xsd:complexType>
    <xsd:complexType name="artifactType">
        <xsd:complexContent mixed="false">
            <xsd:extension base="abstractArtifactType">
                <xsd:attributeGroup ref="genericArtifactAttributeGroup"/>
            </xsd:extension>
        </xsd:complexContent>
    </xsd:complexType>
    <xsd:element abstract="true" name="artifactType" type="abstractArtifactType"/>
    <xsd:element name="test" substitutionGroup="artifactType" type="testType"/>
    <xsd:element name="artifact" substitutionGroup="artifactType" type="artifactType"/>
    <xsd:element name="log" substitutionGroup="artifactType" type="logType"/>
    <xsd:attributeGroup name="genericArtifactAttributeGroup">
        <xsd:attribute name="src" type="xsd:string"/>
        <xsd:attribute name="dest" type="filePathType"/>
    </xsd:attributeGroup>
    <xsd:complexType name="templatesType">
        <xsd:sequence>
            <xsd:element minOccurs="1" maxOccurs="unbounded" name="pipeline">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element minOccurs="1" maxOccurs="unbounded" name="stage" type="stageType">
                        </xsd:element>
                    </xsd:sequence>
                    <xsd:attribute name="name" type="nameType"/>
                </xsd:complexType>
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="environmentsType">
        <xsd:sequence>
            <xsd:element minOccurs="1" maxOccurs="unbounded" name="environment">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element ref="environmentvariables" minOccurs="0" maxOccurs="1"/>
                        <xsd:element minOccurs="0" maxOccurs="1" name="agents" type="environmentAgentsType">
                            <xsd:unique name="uniqueEnvironmentAgentsUuid">
                                <xsd:selector xpath="physical"/>
                                <xsd:field xpath="@uuid"/>
                            </xsd:unique>
                        </xsd:element>
                        <xsd:element minOccurs="0" maxOccurs="1" name="pipelines" type="environmentPipelinesType"/>
                    </xsd:sequence>
                    <xsd:attribute name="name" type="environmentName" use="required"/>
                </xsd:complexType>
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="environmentAgentsType">
        <xsd:sequence>
            <xsd:element minOccurs="0" maxOccurs="unbounded" name="physical">
                <xsd:complexType>
                    <xsd:attribute name="uuid" type="xsd:string" use="required"/>
                </xsd:complexType>
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="environmentPipelinesType">
        <xsd:sequence>
            <xsd:element minOccurs="0" maxOccurs="unbounded" name="pipeline">
                <xsd:complexType>
                    <xsd:attribute name="name" type="nameType" use="required"/>
                </xsd:complexType>
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="agentsType">
        <xsd:sequence>
            <xsd:element minOccurs="0" maxOccurs="unbounded" name="agent">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element minOccurs="0" name="resources" type="resourcesType"/>
                    </xsd:sequence>
                    <xsd:attribute name="hostname" type="xsd:string" use="required"/>
                    <xsd:attribute name="ipaddress" type="xsd:string" use="required"/>
                    <xsd:attribute name="uuid" type="xsd:string" use="required"/>
                    <xsd:attribute name="isDisabled" type="xsd:boolean" use="optional"/>
                </xsd:complexType>
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:simpleType name="nameType">
        <xsd:restriction base="xsd:string">
            <xsd:maxLength value="255"/>
            <xsd:pattern value="[a-zA-Z0-9_\-]{1}[a-zA-Z0-9_\-.]*"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="environmentName">
        <xsd:restriction base="nameType"/>
    </xsd:simpleType>
    <xsd:simpleType name="propertyNameType">
        <xsd:restriction base="nameType">
            <xsd:maxLength value="255"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="middleLengthString">
        <xsd:restriction base="xsd:string">
            <xsd:maxLength value="512"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="nonEmptyString">
        <xsd:restriction base="xsd:string">
            <xsd:pattern value="[\s]*[\S][\s\S]*"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="labelType">
        <xsd:restriction base="xsd:string">
            <xsd:pattern value="(([a-zA-Z0-9_\-.!~*'()#])*[$#]\{[a-zA-Z0-9_\-.!~*'()#]+\}([a-zA-Z0-9_\-.!~*'()#])*)+"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="jobnameType">
        <xsd:restriction base="xsd:string">
            <xsd:maxLength value="255"/>
            <xsd:pattern value="[a-zA-Z0-9_\-.]+"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:attributeGroup name="serverAttributeGroup">
        <xsd:attribute name="artifactsdir" type="xsd:string"/>
        <xsd:attribute name="siteUrl">
            <xsd:simpleType>
                <xsd:restriction base="xsd:string">
                    <xsd:pattern value="https?://.+"/>
                </xsd:restriction>
            </xsd:simpleType>
        </xsd:attribute>
        <xsd:attribute name="secureSiteUrl">
            <xsd:simpleType>
                <xsd:restriction base="xsd:string">
                    <xsd:pattern value="https://.+"/>
                </xsd:restriction>
            </xsd:simpleType>
        </xsd:attribute>
        <xsd:attribute name="purgeStart" type="xsd:double"/>
        <xsd:attribute name="purgeUpto" type="xsd:double"/>
        <xsd:attribute name="jobTimeout" type="xsd:double"/>
        <xsd:attribute name="agentAutoRegisterKey" type="xsd:string"/>
    </xsd:attributeGroup>
    <xsd:attributeGroup name="execAttributes">
        <xsd:attribute name="command" type="commandType" use="required"/>
        <xsd:attribute name="args" type="xsd:string"/>
        <xsd:attribute name="workingdir" type="filePathType"/>
        <xsd:attribute name="timeout" type="xsd:positiveInteger"/>
    </xsd:attributeGroup>
    <xsd:simpleType name="commandType">
        <xsd:restriction base="xsd:string">
            <xsd:pattern value=".*[\S]+.*"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:complexType name="dependsType">
        <xsd:attribute use="required" name="pipeline" type="xsd:string"/>
        <xsd:attribute use="required" name="stage" type="xsd:string"/>
    </xsd:complexType>

    <xsd:complexType name="dependenciesType">
        <xsd:sequence>
            <xsd:element minOccurs="0" maxOccurs="unbounded" name="depends" type="dependsType"/>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:element name="tab">
        <xsd:complexType>
            <xsd:attribute name="name" use="required">
                <xsd:simpleType>
                    <xsd:restriction base="xsd:string">
                        <xsd:maxLength value="15"/>
                    </xsd:restriction>
                </xsd:simpleType>
            </xsd:attribute>
            <xsd:attribute name="path" use="required">
                <xsd:simpleType>
                    <xsd:restriction base="xsd:string">
                        <xsd:pattern value="[\S]+"/>
                    </xsd:restriction>
                </xsd:simpleType>
            </xsd:attribute>
        </xsd:complexType>
    </xsd:element>
    <xsd:simpleType name="filePathType">
        <xsd:restriction base="xsd:string" xml:space="default">
            <xsd:pattern value="([^. ].+[^. ])|([^. ][^. ])|([^. ])"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="timerType">
        <xsd:restriction base="xsd:string" xml:space="default"/>
    </xsd:simpleType>
    <xsd:complexType name="propertiesType">
        <xsd:sequence>
            <xsd:element name="property" minOccurs="1" maxOccurs="unbounded" type="propertyType"/>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="propertyType">
        <xsd:attribute name="name" type="propertyNameType" use="required"/>
        <xsd:attribute name="src" type="middleLengthString"/>
        <xsd:attribute name="xpath" type="middleLengthString"/>
    </xsd:complexType>
    <xsd:complexType name="trackingToolType">
        <xsd:attribute name="link" type="xsd:string" use="required"/>
        <xsd:attribute name="regex" type="xsd:string" use="required"/>
    </xsd:complexType>
    <xsd:complexType name="mingleType">
        <xsd:sequence>
            <xsd:element name="mqlGroupingConditions" minOccurs="0" maxOccurs="1">
                <xsd:simpleType>
                    <xsd:restriction base="xsd:string" xml:space="default"/>
                </xsd:simpleType>
            </xsd:element>
        </xsd:sequence>
        <xsd:attribute name="baseUrl" use="required">
            <xsd:simpleType>
                <xsd:restriction base="xsd:string"/>
            </xsd:simpleType>
        </xsd:attribute>
        <xsd:attribute name="projectIdentifier" use="required">
            <xsd:simpleType>
                <xsd:restriction base="xsd:string">
                   <xsd:pattern value="[^\s]+"/>
                </xsd:restriction>
            </xsd:simpleType>
        </xsd:attribute>
    </xsd:complexType>
    <xsd:element name="filter" type="filterType"/>
    <xsd:complexType name="filterType">
        <xsd:sequence>
            <xsd:element name="ignore" minOccurs="1" maxOccurs="unbounded">
                <xsd:complexType>
                    <xsd:attribute name="pattern" type="xsd:string" use="required"/>
                </xsd:complexType>
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="runIfType">
        <xsd:attribute name="status" use="required">
            <xsd:simpleType>
                <xsd:restriction base="xsd:string">
                    <xsd:enumeration value="passed"/>
                    <xsd:enumeration value="failed"/>
                    <xsd:enumeration value="any"/>
                </xsd:restriction>
            </xsd:simpleType>
        </xsd:attribute>
    </xsd:complexType>
    <xsd:complexType name="onCancelType">
        <xsd:sequence>
            <xsd:element ref="task" minOccurs="0" maxOccurs="1"/>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:element name="oncancel" type="onCancelType"/>
    <xsd:element name="runif" type="runIfType"/>
    <xsd:complexType name="authorizationType">
        <xsd:all>
            <xsd:element name="view" type="authorizedUserListType" minOccurs="0" maxOccurs="1">
                <xsd:unique name="uniqueUserInView">
                    <xsd:selector xpath="user"/>
                    <xsd:field xpath="."/>
                </xsd:unique>
                <xsd:unique name="uniqueRoleInView">
                    <xsd:selector xpath="role"/>
                    <xsd:field xpath="."/>
                </xsd:unique>
            </xsd:element>
            <xsd:element name="operate" type="authorizedUserListType" minOccurs="0" maxOccurs="1">
                <xsd:unique name="uniqueUserInOperate">
                    <xsd:selector xpath="user"/>
                    <xsd:field xpath="."/>
                </xsd:unique>
                <xsd:unique name="uniqueRoleInOperate">
                    <xsd:selector xpath="role"/>
                    <xsd:field xpath="."/>
                </xsd:unique>
            </xsd:element>
            <xsd:element name="admins" type="adminType" minOccurs="0" maxOccurs="1"/>
        </xsd:all>
    </xsd:complexType>
    <xsd:complexType name="authorizedUserListType">
        <xsd:choice minOccurs="1" maxOccurs="unbounded">
            <xsd:element name="user" type="xsd:string"/>
            <xsd:element name="role" type="xsd:string"/>
        </xsd:choice>
    </xsd:complexType>

    <xsd:element name="environmentvariables">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="variable" minOccurs="0" maxOccurs="unbounded">
                    <xsd:complexType>
                        <xsd:simpleContent>
                            <xsd:extension base="xsd:string">
                                <xsd:attribute name="name" use="required"/>
                            </xsd:extension>
                        </xsd:simpleContent>
                    </xsd:complexType>
                </xsd:element>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>

    <xsd:element name="params">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="param" minOccurs="0" maxOccurs="unbounded">
                    <xsd:complexType>
                        <xsd:simpleContent>
                            <xsd:extension base="xsd:string">
                                <xsd:attribute name="name" type="nameType" use="required"/>
                            </xsd:extension>
                        </xsd:simpleContent>
                    </xsd:complexType>
                </xsd:element>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>

    <xsd:simpleType name="tfsWorkspaceType">
        <xsd:restriction base="xsd:string">
            <xsd:maxLength value="30"/>
        </xsd:restriction>
    </xsd:simpleType>
</xsd:schema>
