Composer找不到配置文件-在Windows上使用Jenkins

时间:2019-01-31 01:43:56

标签: php jenkins ant composer-php

我有一个试图执行Composer install的Ant构建脚本,但是通过Jenkins执行时出现此错误:

     [exec] Composer could not find the config file: C:\ProgramData\ComposerSetup\bin
     [exec] To initialize a project, please create a composer.json file as described in the https://getcomposer.org/ "Getting Started" section
     [exec] Result: 1
     [echo] composer update complete

这是Ant的目标:

<target name="self-update"
        if="composer.self-update"
        unless="composer.installed"
        description="Self-update Composer">
    <echo message="Self-updating composer" level="debug"/>
    <exec executable="${composer.phar}">
        <arg value="self-update" />
        <arg value="--quiet" />
        <arg value="--no-interaction" />
    </exec>
    <echo message="composer self-update complete" level="debug"/>
</target>

但是,在本地运行Ant构建时,此方法工作正常。

有人说要删除作曲家安装程序设置的环境变量;但是它似乎并没有改变任何东西。

1 个答案:

答案 0 :(得分:0)

有一个名为COMPOSER的环境变量,已设置为C:\ProgramData\ComposerSetup\bin。通过Environment Variables控制面板看不到该变量。

我可以通过将env key="composer"设置为""来解决此问题。

<target name="composer"
        depends="init, self-install, self-update"
        if="composer.run">
    <condition property="composer.command" value="update" else="install">
        <available file="${composer.lock}"/>
    </condition>
    <echo message="Beginning composer ${composer.command}" level="debug"/>
    <exec executable="php">
        <env key="composer" value=""/>
        <arg value="${composer.phar}"/>
        <arg value="${composer.command}"/>
        <arg value="--verbose"/>
        <arg value="--no-interaction"/>
        <arg value="--optimize-autoloader"/>
        <arg value="--prefer-dist"/>
    </exec>
    <echo message="composer ${composer.command} complete" level="debug"/>
</target>

也可以将其设置为composer.json