如何在C#项目中使用TeamCity维护每日SNAPSHOT构建

时间:2017-04-10 10:19:15

标签: maven continuous-integration teamcity nexus snapshot

我正在接管一个由大约15个项目组成的项目,这些项目由Maven + Nexus OSS + TeamCity完成了持续集成实践(这种做法已经停止,我需要在新环境中重新启动)并且已经开发出来了使用C#。

我得到的,除了那些C#解决方案本身,每个项目都是POM,而另一个项目的另一个父POM(不包含任何代码)有父母的。这些开发POM仅对SNAPSHOT版本具有相互依赖性,因此构建顺序至关重要。但是这些POM我不需要任何VS插件,这意味着(我猜)编译过程不是由Maven完成的,而是由TeamCity(VS runner)完成的。我拥有的Maven脚本可能只负责下载依赖项,验证和安装/部署/发布。不幸的是,我无法找到任何TeamCity配置,所以我不知道以前是怎么做到的。

编辑:

我会尝试放置一些POM和脚本文件,看看是否有人可以看到构建过程的一些线索。

我从SVN获得的文件主要有三种类别:

1)C#源代码和项目/解决方案文件。每个解决方案都有一个“依赖性”'包含所有依赖项的文件夹,都包含在第三方dll上的其他项目中,以便开发人员在签出此解决方案后立即在VS中构建此解决方案。

2)(开发)POM s。

首先,我有父项目的POM。该项目不包含任何代码,只包含POM和一些脚本(其他项目也有类似的文件)。 POM看起来像这样:

<modelVersion>4.0.0</modelVersion>
<groupId>MY.GROUP</groupId>
<artifactId>configuration</artifactId>
<version>1.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Configuration</name>
... 
<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.8</version>
                <executions>
                    <execution>
                        <id>purge-local-dependencies</id>
                        <phase>clean</phase>
                        <goals>
                            <goal>purge-local-repository</goal>
                        </goals>
                        <configuration>
                            <!-- Whether to purge only snapshot artifacts. -->
                            <snapshotsOnly>true</snapshotsOnly>
                            <actTransitively>false</actTransitively>
                            <reResolve>false</reResolve>
                        </configuration>
                    </execution>
                    <execution>
                        <id>unpack-dependencies</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>unpack-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${dependencies.directory}</outputDirectory>
                            <markersDirectory>${dependencies.markers.directory}</markersDirectory>
                            <useBaseVersion>true</useBaseVersion>
                            <overWriteReleases>true</overWriteReleases>
                            <overWriteSnapshots>true</overWriteSnapshots>
                            <overWriteIfNewer>true</overWriteIfNewer>
                            <excludeTransitive>false</excludeTransitive>
                            <useSubDirectoryPerArtifact>true</useSubDirectoryPerArtifact>
                            <stripVersion>true</stripVersion>
                            <stripClassifier>true</stripClassifier>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.4</version>
                <executions>
                    <execution>
                        <id>assembly-single-zip</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <finalName>${project.build.finalName}</finalName>
                            <descriptors>
                                <descriptor>${assembly.file}</descriptor>
                            </descriptors>
                            <attach>false</attach>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <version>2.8.1</version>
                <executions>
                    <execution>
                        <id>deploy-file-snapshot</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>deploy-file</goal>
                        </goals>
                        <configuration>
                            <file>${deploy.file}</file>
                            <repositoryId>${nexus.repository.id}</repositoryId>
                            <groupId>${project.groupId}</groupId>
                            <artifactId>${project.artifactId}</artifactId>
                            <version>${project.version}</version>
                            <url>${nexus.repository.url}</url>
                            <pomFile>${nexus.deploy.pom}</pomFile>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <version>2.5.2</version>
                <configuration>
                    <preparationGoals>clean</preparationGoals>
                    <tagBase>${release.tagBase}</tagBase>       
                    <tagNameFormat>@{project.version}</tagNameFormat>                       
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>
...

在这里,我们看到构建中使用的插件是dependency(下载依赖项),&#39;程序集&#39; (打包),deploy(将文件部署到Nexus)和release - 坦率地说,我无法弄清楚它是如何使用的。我所拥有的脚本(我稍后将描述)不会明确地使用它,它似乎不会在其他标准构建阶段执行。

在每个解决方案中,POM都有configuration的父级。它们看起来像这样:

ProjA

<parent>
    <groupId>MY.GROUP</groupId>
    <artifactId>configuration</artifactId>
    <version>1.0.1-SNAPSHOT</version>
</parent>
<groupId>MY.GROUP</groupId>
<artifactId>ProjA</artifactId>
<version>1.1.2-SNAPSHOT</version>
<packaging>pom</packaging>
<name>ProjA</name>
...     
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-deploy-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-release-plugin</artifactId>
        </plugin>
    </plugins>
</build>
...

在依赖ProjB的{​​{1}}中,ProjA是这样的:

POM

3)然后是一些.bat脚本以及deploy.pom和release.pom。 <parent> <groupId>MY.GROUP</groupId> <artifactId>configuration</artifactId> <version>1.0.1-SNAPSHOT</version> </parent> <groupId>MY.GROUP</groupId> <artifactId>ProjB</artifactId> <version>1.2.1-SNAPSHOT</version> <packaging>pom</packaging> <name>ProjB</name> ... <dependencies> <dependency> <groupId>MY.GROUP</groupId> <artifactId>ProjA</artifactId> <version>1.1.2-SNAPSHOT</version> <type>zip</type> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-deploy-plugin</artifactId> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-release-plugin</artifactId> </plugin> </plugins> </build> ... deploy pom只是简单地替换版本号并声明依赖项:

release pom部署.pom:

ProjA

<?xml version="1.0" encoding="utf-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>MY.GROUP</groupId> <artifactId>ProjA</artifactId> <version>1.1.2-SNAPSHOT</version> <packaging>pom</packaging> ..<dependencies>...</dependencies> 我认为这意味着SNAPSHOT版本的部署,如版本号所示。

deploy基本相同,但将版本更改为发布版本(在release.pom中为1.1.1)。

在每个解决方案中,我还有一些脚本,我认为这些脚本由ProjA调用。 a)一个名为TeamCity的文件,它基本上调用download.bat然后调用mvn -U clean。 b)名为mvn -U validate的文件,基本上调用upload.bat然后调用mvn prepare-package。在这两个脚本中,我们传递了一些mvn选项,如mvn verify。从父-DDeployPomFile, -DNexusUrl, -DRepositoryId我们可以看到一些插件也在这些脚本中执行。我想在POM执行VS构建之前调用download.bat并在构建之后调用TC(假设构建的目标是发布最新版本)。

以上是我得到的全部。我怀疑我仍然遗漏了一些upload.bat配置,因为它们没有存储在TeamCity中。但无论如何,有人可以帮助弄清楚如何管理每日构建吗?非常感谢你!

0 个答案:

没有答案