0

I'm trying to set my MAC to connect to Jenkins and be ready to build automatically. I've managed to create service that connects to Jenkins, but something is wrong.

This is my plist file:

<key>Label</key>
    <string>com.example.ci</string>
    <key>ProgramArguments</key>
    <array>
        <string>sh</string>
        <string>/Users/Shared/Jenkins/Home/my_scripts/run_jenkins.sh</string>
    </array>
    <key>KeepAlive</key>
    <true/>
    <key>StandardOutPath</key>
    <string>/Users/Shared/Jenkins/Home/stdout.log</string>
    <key>StandardErrorPath</key>
 <string>/Users/Shared/Jenkins/Home/error.log</string>

this is my run_jenkins.sh:

cd /Users/Shared/Jenkins/Home/
sudo -u jenkins java -jar slave.jar -jnlpUrl http://secret.mission:8080/computer/ios-slave/slave-agent.jnlp -secret 841557ed7843ac76fe1618e375

PROBLEM:

 $ /usr/bin/security find-identity -p codesigning -v
     0 valid identities found

this happens when I try to build right after start-up. Of course after that build fails.

When I go sudo launchctl unload /Library/LaunchDaemons/org.jenkins-ci.plist and then sudo launchctl load /Library/LaunchDaemons/org.jenkins-ci.plist the result is :

$ /usr/bin/security find-identity -p codesigning -v
  [.. ]
     4 valid identities found

and build is succeeded. Why is that MAC can't find those profiles when it runs from start-up and how to fix this?

EDIT

I've edited my plist file:

    <key>UserName</key>
    <string>jenkins</string>
    <key>Label</key>
    <string>com.example.ci</string>
    <key>ProgramArguments</key>
    <array>
        <string>sudo</string>
        <string>-u</string>
        <string>jenkins</string>
        <string>/usr/bin/java</string>
        <string>-Djava.awt.headless=true</string>
        <string>-jar</string>
        <string>/Users/Shared/Jenkins/Home/slave.jar</string>
        <string>-jnlpUrl</string>
        <string>http://secret.mission:8080/computer/ios-slave/slave-agent.jnlp
</string>
        <string>-secret</string>
        <string>841557ed7843ac76fe1618e375
</string>
    </array>
    <key>KeepAlive</key>
    <true/>
    <key>StandardOutPath</key>
    <string>/Users/Shared/Jenkins/Home/stdout.log</string>
    <key>StandardErrorPath</key>
    <string>/Users/Shared/Jenkins/Home/error.log</string>

and still same situation...

4
  • Your codesigning identities are in your user account's keychain. If you log in as a different user and run the sudo .. unload/load, I'm pretty sure it'll fail as well. You probably need to be logged in as that user so this works.
    – Daniel Beck
    Commented Feb 25, 2014 at 9:44
  • Sounds about right, but how to achieve this? I set up that jenkins should be logged in as default user. Don't know what else I can configure.
    – mmmm
    Commented Feb 25, 2014 at 9:46
  • Don't create a system-wide launch daemon. Try creating a user-specific launch agent instead (in ~/Library/LaunchAgents)
    – Daniel Beck
    Commented Feb 25, 2014 at 9:48
  • I'd actually prefer if you wrote the answer, including all the information some one else might need to make it work. This way, others can benefit from this question as well!
    – Daniel Beck
    Commented Feb 25, 2014 at 10:35

2 Answers 2

0

Does this script require any variables that are set in your shell profile to work properly by any chance?

I've definitely run into problems with launchd running scripts on startup that always worked fine when I ran them on the command line.

You could maybe attempt to include the loading of your .bash_profile or .bashrc (or both if necessary) at the top of the script that launches the slave and see if that helps.

5
  • nope, it is run by "sh my_script.sh" as You can see <string>sh</string><string>/Users/Shared/Jenkins/Home/my_scripts/run_jenkins.sh</string>. Include is just # .bashrc! at the top?
    – mmmm
    Commented Feb 24, 2014 at 17:31
  • Yes, but when you run sh my_script.sh from a terminal, you have a bunch of variables that are initiated with your terminal (look at the output of env or set). Launchd will not all of these load these at boot, so it might be that your script is dependent on one of these. You could try adding the lines I suggested to eliminate this being the cause.
    – arco444
    Commented Feb 24, 2014 at 17:37
  • well I've added #!/bin/bash because I couldn't find neither bash_profile nor bashrc, but the problem is still there..
    – mmmm
    Commented Feb 25, 2014 at 9:01
  • I'm not talking about the shebang, that should be #!/bin/bash as you have. I'm talking about including your profile scripts. They should be in your home directory. Include them in your script using the . or source operator e.g. . /Users/you/.bashrc
    – arco444
    Commented Feb 25, 2014 at 9:42
  • I've been looking there and it wasn't there.. there is only .bash_history.
    – mmmm
    Commented Feb 25, 2014 at 9:44
0

The solution was very simple:

my plist file was in /Library/LaunchDaemons/ directory, in which plist files starts automatically on system start-up, but the issue was that user wasn't proper, despite all the variables in commands within this file.

So all I needed to do was to put .plist file from above to folder [jenkins home]/Library/LaunchAgents .

NOTICE that I set up jenkins as a default user to log in!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .