3

When I build project from terminal by using 'xcodebuild' command I succeed, but when I try to do run same script from cron task I receive error "Code Sign error: The identity '****' doesn't match any valid certificate/private key pair in the default keychain"

I think problem is in settings and permissions of crontab utility, it seems crontab does not see my keychain

Can anyone provide me terminal command how to make my keychain visible for crontab

Dmitry Pilipenko
  • 339
  • 6
  • 16

3 Answers3

2

I encountered a similar issue with trying to build nightly via cron. The only resolution I found was to create a plist in /Library/LaunchDaemons/ and load it via launchctl. The key necessary is "SessionCreate" otherwise you will quickly run in to problems similar to what was encountered with trying to use cron -- namely that your user login.keychain is not available to the process. "SessionCreate" is similar to "su -l" in that (as far as I understand) it simulates a login and thus default keychains you expect will be available; otherwise, you are stuck with only the System keychain despite the task running as your user.

I found the answers (though not the top answer currently) here useful in troublw shooting this issue: Missing certificates and keys in the keychain while using Jenkins/Hudson as Continuous Integration for iOS and Mac development

Community
  • 1
  • 1
Nathan
  • 21
  • 2
0

You execute your cron job with which account ?

most probably the problem !! You can add

echo `whoami`

at the beginning of your script to see with which user the script is launched.

Also when a Bash script is launched from cron, it don't use the same environment variable (non login shell) as when you launch it as a user.

ericc
  • 741
  • 3
  • 8
  • 19
  • user is the same as I use from terminal – Dmitry Pilipenko Dec 26 '11 at 09:14
  • So if it's the same user, it's probably a problem with the environment.
    When you start a bash shell, you have 3 modes: **Login Interactive Shell**, when you logon from the console, **Non-Login Interactive Shell**, when you start from a terminal, and **Non-Interactive Shell** when it's launched from a script.
    In the third case, it don't read the ~/.bash_profile file.So you probably have a problem with the $PATH which is defined in this file.You may be add "source ~/.bash_profile" in your script to redefine the correct variables or redefine the correct path in the script.
    – ericc Dec 26 '11 at 11:52
0

When the script launches from cron, it doesn't load your $HOME/.profile (or .bash_profile). Anything you run from cron has to be 100% self-sufficient in terms of it's environment. I'd suggest you make yourself a file called something like "set_build_env.sh" It should contain everything from your .profile that you need to build, such as $PATH, $HOME, $CLASSPATH etc. Then in your build script, load set_build_env.sh using the dot notation or source cmd as ericc said. You should also remove the build-specific lines from your.profile and then source set_build_env from there too so only one place to maintain. Example: source /home/dmitry/set_build_env.sh #absolute path . /home/dmitry/set_build_env.sh #dot-space notation same as "source"

Jimko
  • 31
  • 4