【问题标题】:Doing a git push OVER HTTPS from within a build script on Xcode server从 Xcode 服务器上的构建脚本中执行 git push OVER HTTPS
【发布时间】:2015-07-10 14:53:16
【问题描述】:

首先我要提到的是我不能使用 ssh。

除此之外,如果有人能提供帮助,我将永远感激不尽。

我需要在我的机器人上运行一个构建后脚本,该脚本创建一个标签并在构建成功时将其推送到远程。我尝试将它作为在机器人上定义的“发布”脚本、作为项目构建设置中的“构建阶段”以及作为我用于 CI 的自定义共享方案中的构建后脚本运行。脚本如下所示:

if [ -z "$PROJECT_DIR" ]; then
    echo "No project dir variable"
else
    cd $PROJECT_DIR;
    echo "PROJECT_DIR is $PROJECT_DIR";
    echo "Directory is $(pwd)";

    git config user.email "myself@mycompany.com"
    git config user.name "myself"
    CURRENTTAG=$(git describe --abbrev=0 --tags);
    echo "CURRENTTAG is $CURRENTTAG";
    CURRENTTAG_PRE=`echo $CURRENTTAG | awk -F "_" '{print $1}'`;
    echo "CURRENTTAG_PRE is $CURRENTTAG_PRE";
    CURRENTTAG_POST=`echo $CURRENTTAG | awk -F "_" '{print $2}'`;
    echo "CURRENTTAG_POST is $CURRENTTAG_POST";

    if [ -z "$CURRENTTAG_POST" ]; then
        echo "catastrophic failure"
        exit 0
    else
        CURRENTTAG_POST=$(($CURRENTTAG_POST + 1));
        SPACE="_";
        NEW_TAG=$CURRENTTAG_PRE$SPACE$CURRENTTAG_POST;
        echo "NEW_TAG is $NEW_TAG";
        git tag -a $NEW_TAG -m "$NEW_TAG";
        git push origin "$NEW_TAG"

        echo "New tag $(git describe --abbrev=0 --tags) created"
    fi
fi

所以,git config 命令的 hack 可以阻止 git 询问机器人“请告诉我你是谁”。但是,一旦机器人通过了这个, git push 就会失败,并显示以下内容:

fatal: could not read Password for 'https://myself@mygitremote.com': Device not configured

任何人都可以提供任何基于 HTTPS 的建议,告诉我如何解决这个问题吗?

顺便说一下,我使用的是 Xcode 6.4 和 Server 4.1.2。

谢谢。

编辑:我已经看到了很多解决方案,这些解决方案都是从 sudo 进入 _xcsbuildd 的 shell 开始的。在 Xcode Server 4.1 中肯定没有 _xcsbuildd 的主目录,所以你不能“git config --global”任何东西。

【问题讨论】:

  • 您是否在.netrc 文件或其他可以读取 git push 的地方输入了密码?
  • 问题是运行脚本的 _xcsbuildd 用户实际上并没有 $HOME 或 shell。我试着给它一个外壳,它开始在其他地方破坏其他东西。这使得任何基于用户级设置的解决方案都不可能。
  • 注意你不需要运行git config --global——如果你想拥有每个存储库的凭据。如果您运行git config,那么它只会将更改应用到该存储库。

标签: ios xcode git continuous-integration xcode-server


【解决方案1】:

我遇到了类似的问题。我试图将更改从机器人的预触发脚本推送到 git 远程存储库,每次收到:

fatal: could not read Username for 'http://...': Device not configured

我的最终解决方案是将凭据存储在_xcsbuildd 用户的钥匙串中:

# login as a _xcsbuildd user
sudo -u _xcsbuildd /bin/bash
# store credentials in the default osx keychain
git credential-osxkeychain store https://github.com
# copy added credentials from `login` keychain to `System` keychain

【讨论】:

    猜你喜欢
    • 2015-01-10
    • 2020-06-29
    • 2014-10-08
    • 2023-04-07
    • 1970-01-01
    • 2016-08-03
    • 2017-01-01
    • 2019-09-03
    • 1970-01-01
    相关资源
    最近更新 更多