Unity: UnityEngine.Advertisements.dll could not be found

If you’re seeing an error when building a Unity project with Jenkins on Windows, and it looks something like this…

error CS0006: Metadata file 'Unity/cache/packages/packages.unity.com/com.unity.ads@2.0.3/UnityEngine.Advertisements.dll' could not be found

…then it’s probably caused by Unity PackageManager (introduced in 2017.2) looking a file in the wrong place. Jenkins uses the SYSTEM account to access files, but Unity doesn’t play nicely with this until version 2018.1.

To solve the problem setup two Environment Variables as seen below to point to the correct location for the files OR install unity 2018.1 which (apparently) has a fix in it. If you use the Environment variables then you’ll need to restart your PC before it’ll work.

Env

Hope it helps

 

Setup an OSX Slave for a Windows Jenkins Instance

So, I’ve been working on an iOS project in Unity and wanted to build on a PC and just use a Mac for the signing step. This allows me to throw processing power at the build (the PC) and just use a low-end Mac Mini to handle the less labour intensive signing.

Technically, a Mac isn’t needed in the pipeline (PC’s can handle the sign) but I’m still a bit sceptical about signing final release builds on a PC, and would prefer to keep things safe by signing on the hardware and tools that Apple recommends.

Quick tutorial on setting up an OSX slave that can be used from the PC…

  1. Setup Jenkins on PC and Mac (I’m using 2.102 and it’s quite stable)
  2. Add a Slave Node
    1. In Jenkins, go to Manage Jenkins->Manage Nodes->New Node
    2. Enter a name (“Slave OSX” or similar)
    3. Select “Permanent Agent”
    4. Click “OK”
  3. On the page that follows (See below): –
    1. Set the Remote Root Directory for the slave (For me it’s /Users/Shared/Jenkins/slave)
    2. In Launch Method, select “Launch slave agents via SSH”
      1. Enter the IP of the slave
      2. Click “Add” on credentials to enter credentials that will allow your PC to connect to the Mac (See below for more info)
      3. Under “Host Key verification Strategy” I use “Manually provided key Verification Strategy”. Note: This is the rsa key of the Mac you’re connecting to. It IS NOT the rsa key needed to connect to the Windows PC. The rsa for the slave Mac can be found by typing “ssh-keyscan -t rsa [IP of Slave] on a terminal session on the slave Mac

AddSlaveNode

As mentioned above in point 3.2.2, the credentials for connecting to the Mac have to be set up. After clicking the “Add” button do the following: –

  1. Set the scope to “System”
  2. Add the username that you’ll be using to log in to the Mac
  3. Set the private key to the private key generated for this PC. See my other post here to get info on how to do this. The same post will talk you through configuring the Mac to work with password-less access via an authorized_keys file

ConfigCredentials

And that’s it. When you launch the node it should connect to the Mac and you’ve got a Mac slave. I’ll add another post on how to setup the signing soon.

 

 

 

Setup a mac to allow ssh login without a password (PC to Mac in this example)

We want to be able to login to a mac using ssh but don’t want to type a password every time. This is done by allowing Remote Login for a given user on the Mac and adding a public key to the Mac for the PC you’re logging in from.

  1. On the mac, make sure the user allows “Remote Login”. You’ll find this in Settings->Sharing
    1. Tick “Remote Login” and make sure the user you’re logging in as is included in the list on the right (click the ‘+’ if not)
  2. Open a bash commandline on the PC (Git Bash will do the job)
    1. ssh-keygen –t rsa
    2. press Enter until the command exits (passwords etc all blank)
  3. You now have a public key for the PC
  4. ssh to the mac
    1. ssh [user]@[IP] (in my case, ssh jenkins@JENKINS_SLAVE)
    2. Make sure you have a .ssh directory in the home directory (the one that you’re in straight after logging in). If not, mkdir .ssh
  5. Open another bash commandline on the PC
    1. cd to the directory where the id_rsa.pub was created. In my case: –
    2. cd /c/Users/andygreen/.ssh
    3. Copy the .pub to the mac
      1. scp ./id_rsa.pub jenkins@JENKINS_SLAVE:/Users/Shared/Jenkins/.ssh
    4. Go back to the bash session that’s logged into the Mac and copy the public key to an “authorized_keys” file so it’ll be checked when logging in
      1. cd .ssh
      2. cat id_rsa.pub >> authorized_keys

That should do it. The next ssh jenkins@JENKINS_SLAVE will login without asking for a password

Also, worth noting that Sierra or above will need to be a 2048 bit rsa or they won’t work. See here for more info

 

 

Notes from setting up Jenkins as another user

Setting up Jenkins to run as another user

  • So, long story but it’s often helpful to do this to avoid problems with rights or setting up Jenkins to work as a desktop user

This file:

/etc/newsyslog.d/jenkins.conf

Needs to look like this: –

/var/log/jenkins/jenkins.log jenkins:jenkins 644 3 * $D0 J

Make sure it’s root:wheel (sudo chown root:wheel it)

See here for more details: – (Ignore the URL, nothing specific to Yosemite)

http://stackoverflow.com/questions/26483089/launchd-is-not-starting-jenkins-server-on-os-x-yosemite

Run Jenkins as another user will save a lot of messing around

This file:

/Library/LaunchDaemons/org.jenkins-ci.plist

Needs to have the group ‘wheel’ (users that can use su)

Needs to have the user ‘andygreen’ (or whatever you’re using as your desktop user)

NB: LaunchDaemons cannot have group or world write access or they won’t run. This took a while to figure out. Kept getting a permissions problem when I tried to launch it

To stop and start (respectively): –

  • sudo launchctl unload -w /Library/LaunchDaemons/org.jenkins-ci.plist
  • sudo launchctl load -w /Library/LaunchDaemons/org.jenkins-ci.plist

chown (-R) the jenkins directory (Users/Shared/jenkins) to andygreen:wheel