【问题标题】:Xcode Server 4.0 git push from build trigger scriptXcode Server 4.0 git push 来自构建触发脚本
【发布时间】:2015-01-10 00:37:36
【问题描述】:

我为托管在 github 上的项目安装了 Xcode Bot。我按照步骤和设置机器人来使用我现有的 SSH 密钥。验证成功,项目将checkout并构建。

然后,我在预触发操作中添加了一个 shell 脚本,它增加 plist 中的版本,标记它,并将更改回 github。

但是,当我尝试从 shell 脚本执行 git push 时,我得到了这个:

-- 推送到 git@github.com:spex-app/spex-ios.git 权限被拒绝(公钥)。

致命:无法从远程存储库读取。


为什么服务器会成功签出我的项目但无法推送更改。我注意到用户是_xcsbuildd。我尝试将 .ssh 密钥复制到该 /var/_xcsbuildd/.ssh 中,但这也不起作用。

【问题讨论】:

  • 能否分享一下用于增加内部版本号并推送到 git 的脚本?
  • #!/bin/s # rev count for commits as minor version (e.g 1.0.0.<rev_count>) buildNumber=$(git rev-list HEAD | wc -l | tr -d ' ') echo "Build Number: $buildNumber" /usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "MyProject/MyProject.plist" git tag -a "$buildNumber" -m "$buildNumber" git push --tags
  • 上面的脚本只是用来自 repo 的 rev 提交标记了次要版本。

标签: ios xcode ssh-keys osx-server xcode-server


【解决方案1】:

我想通了。您需要为 _xcsbuildd 用户创建新密钥。然后将它们添加到 github。本帖底部:https://devforums.apple.com/message/1054122#1054122

sudo -u _xcsbuildd /bin/bash
ssh-keygen -t rsa -C "your_email@example.com"
ssh -T git@github.com

【讨论】:

    【解决方案2】:

    考虑到我在整个网络上找到的许多其他答案(以及关于这个问题),我已经有了在 Xcode 6 中完成这项工作的步骤。首先,执行 dmclean 所述的上述内容(进行一些更改)在您的构建服务器上:

    sudo -u _xcsbuildd /bin/bash
    ssh-keygen -t rsa -b 4096 -C "your_email@example.com" (when asked for a keyphrase, just hit return)
    ssh -vT git@github.com (this will show you debugging output - you should not have to enter a keyphrase and it should successfully get to git)
    

    现在,您需要在您的 git 帐户中设置这个新的公钥。请按照以下步骤操作:(第 4 步)https://help.github.com/articles/generating-ssh-keys/

    我假设您的项目有一个构建脚本。我们的项目有一个 Share Extension 和一个 Watch Extension。我希望每个版本号都增加(并且每个版本号都相同)。我们的版本号采用 A.B.C.D (Major.Minor.Patch.build) 格式。此“运行脚本”位于主项目的“构建阶段”中。这是我们的脚本:

    #!/bin/sh
    # Auto Increment Version Script
    # set CFBundleVersion to 1.0.0.1 first!!!
    # the perl regex splits out the last part of a build number (ie: 1.1.1.1) and increments it by one
    # if you have a build number that is more than 4 components, add a '\d+\.' into the first part of the regex. If you have less remove one
    buildPlist=${INFOPLIST_FILE}
    newVersion=`/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$buildPlist" | /usr/bin/perl -pe 's/(\d+\.\d+\.\d+\.)(\d+)/$1.($2+1)/eg'`
    echo $newVersion;
    /usr/libexec/PListBuddy -c "Set :CFBundleVersion $newVersion" "$buildPlist"
    /usr/libexec/PListBuddy -c "Set :CFBundleVersion $newVersion" "$SRCROOT/${PRODUCT_NAME} Extension/Info.plist"
    /usr/libexec/PlistBuddy -c "Set :CFBundleVersion $newVersion" "$SRCROOT/${PRODUCT_NAME} WatchKit Extension/Info.plist"
    /usr/libexec/PlistBuddy -c "Set :CFBundleVersion $newVersion" "$SRCROOT/${PRODUCT_NAME} WatchKit App/Info.plist"
    echo "Trying Git Config"
    git config user.email "your_email@example.com"
    git config user.name "XCode Build Server"
    echo "Trying Git Commit"
    git commit -a -m "Updated Build Numbers"
    echo "Trying Git Push"
    git push
    

    如果它不起作用,请查看构建日志中的输出(在集成下)。

    Some of the problems I encountered:
    

    由于 _xcsbuildd 并没有真正的 $HOME 我必须进行 git 配置,否则我会遇到 git 不知道我是谁的错误(身份错误)。如果我在 RSA 密钥中放置了一个关键字,那么在尝试推送时它会给我公钥错误(我花了一点时间才弄清楚要取出关键字以使其工作)。

    我希望这对某人有所帮助。

    【讨论】:

    • 我也有问题,如果您手动转到构建服务器中的目录,您可以尝试所有命令。我还必须在配置文件中配置 push.default 行为,我在服务器的命令行上使用“git config --global push.default simple”全局设置配置文件,或者你可以在脚本中不使用 - -全局选项
    • 我还必须使用相同的 Xcode 服务器 bot 用户并使用 ssh 密钥克隆我的 repo,并创建一个新的 bot,以便它使用这些特定的凭据。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-02
    • 2015-09-05
    相关资源
    最近更新 更多