Search code examples
iosxcodegitcontinuous-integrationxcode-server

Doing a git push OVER HTTPS from within a build script on Xcode server


The first thing I should mention is that I can't use ssh.

With that out of the way, if anyone can help I'll be eternally grateful.

I need to run a post-build script on my bot which creates a tag and pushes it to the remote upon build success. I've tried running it as a "post" script defined on the bot, as a "build stage" within the project build settings, and as a post-build script in the custom shared scheme I'm using for CI. The script looks like this:

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

So, the hack with the git config commands is there to stop git from asking the bot "Please tell me who you are". Once the bot gets past that, though, the git push fails with the following:

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

Can anyone offer any HTTPS-based suggestions as to how I can get past this?

Incidentally, I'm on Xcode 6.4 and Server 4.1.2.

Thanks.

EDIT: I've seen a lot of solutions out there which start out by sudoing into _xcsbuildd's shell. In Xcode Server 4.1 there is most certainly not a home directory for _xcsbuildd, so you can't "git config --global" anything.


Solution

  • I had the similar problem. I was trying to push changes to git remote repository from bot's pre-trigger script and each time I received:

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

    My final solution was to store credentials in the keychain for the _xcsbuildd user:

    # 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