【问题标题】:Bamboo SCP Task without maintaining directory structureBamboo SCP 任务无需维护目录结构
【发布时间】:2023-11-21 15:47:02
【问题描述】:

我似乎无法弄清楚如何使用 SCP 将我的构建目录的内容移动到服务器而不复制实际的构建文件夹。我目前的流程是这样的:

  1. Bamboo build 从 Stash 签出源代码
  2. Ant 将创建一个构建目录并将所有必要的文件复制到其中
  3. 然后创建一个共享工件。 (构建目录本身)

所以我的工件结构看起来像这样

build/
- img/
- css/
- index.html

当我复制到服务器时,我总是在服务器上获取构建文件夹本身。所以我的根文件夹最终看起来像: /root/build/rest_of_files

我想要实现的是从构建目录复制所有文件并将它们放在根级别。所以我的最终根文件夹如下所示:

root/
- img/
- css/
- index.html

我尝试了不同的本地路径,使用和不使用 ant 模式。我已经为工件本身尝试了不同的模式,但我似乎无法弄清楚我需要做什么。

我希望这很清楚。

【问题讨论】:

    标签: ant scp bamboo bitbucket-server


    【解决方案1】:

    好的,我想出了一种方法来完成我想做的事情。基本上,我最终在我的 ant 构建文件中创建了更多目标,这些目标(重新)移动文件以实现我想要的结构。

    <?xml version="1.0" encoding="utf-8"?>
    <project name="my_project_name" basedir="." default="build">
        <!-- dev directory -->
        <property name="dev.dir" value="dev"></property>
        <!-- public directory -->
        <property name="public.dir" value="${dev.dir}/public/"></property>
        <!-- output directory -->
        <property name="build.dir" value="build"/>
        <!-- public_html directory -->
        <property name="web.dir" value="${build.dir}/public_html/"></property>
    
        <!-- create the build directory -->
        <target name="migrate" description="Make required directories">
            <echo message="Creating directories."/>
            <!-- make the build directory if it doesn't exist -->
            <mkdir dir="${build.dir}/"/>
            <!-- make the public_html directory -->
            <mkdir dir="${web.dir}/"/>
            <!-- call our target that copies the files to the build folder -->
            <antcall target="copyToBuild"/>
        </target>
    
        <!-- list of includes -->
        <target name="copyToBuild" description="Copy files to build folder">
            <echo message="Building."/>
            <!-- copy to the build directory -->
            <copy todir="${build.dir}">
                <fileset dir="${dev.dir}">
                    <!-- includes -->
                    <include name="**"></include>
                    <!-- excludes -->
                    <exclude name="build.xml"></exclude>
                    <exclude name="public/**"></exclude>
                </fileset>
            </copy>
            <!-- copy files to the public_html directory -->
            <copy includeEmptyDirs="true" todir="${web.dir}">
                <fileset dir="${public.dir}">
                    <include name="**"></include>
                    <!-- exclude the less directory -->
                    <exclude name="**/less/**"></exclude>
                </fileset>
            </copy>
    
            <!-- call the clean target -->
            <antcall target="clean"/>
        </target>
    
        <!-- Clean the root folder -->
        <target name="clean" description="Clean the root directory">
            <echo message="Cleaning."></echo>
            <!-- delete all except the build directory -->
            <delete includeemptydirs="true">
                <fileset dir="${basedir}" includes="**/*">
                    <include name="**/*"></include>
                    <exclude name="build/**"></exclude>
                </fileset>
            </delete>
            <!-- delete the dev folder -->
            <delete dir="${dev.dir}"></delete>
            <!-- copy files to the root directory -->
            <copy todir="${basedir}">
                <fileset dir="${build.dir}">
                    <include name="**/*"></include>
                </fileset>
            </copy>
            <!-- delete the build directory -->
            <delete dir="${build.dir}"></delete>
            <!-- delete the public directory -->
            <delete dir="${public.dir}"></delete>
        </target>
    </project>
    

    【讨论】:

    • 是否可以提供有关如何实现此目的的更多详细信息?我有完全相同的问题,但这个答案不清楚。
    • @Arashsoft 抱歉耽搁了。我找到了项目和文件,并将 antfile.xml 的代码添加到了答案中。基本上发生的事情是我正在创建目录,并将所有必要的文件移动到根目录并删除不需要的文件。我确信有更好的方法可以做到这一点,但这是我当时想出的。