overwatering.org

blog

about

I’ve had to configure build promotions with Jenkins on two separate projects now, as it’s not as straight forward as the promotoed builds plugin may make it seem, it’s about time I blogged this. At least for Future-Giles’ benefit.

  1. Install the Promoted Builds plugin.

  2. Select the build job that you want to be able to promote builds for, and make sure that it is storing your artifacts. I recommend creating an artifacts directory in the root of your workspace. Configure the job to store everything in that directory. Then begin your build with a task like so:

    desc "Removes all pre-existing artifacts"
    task :clean do
      rm_rf "artifacts/*.*"
    end
    

    And at the end of the build, publish your artifacts to this directory:

    def artifact(path)
      mkdir_p "artifacts"
      cp path, "artifacts/"
    end
       
    desc "Publish the iOS app as an artifact"
    task :publish => :build do
      artifact(config[:ios][:package_path])
    end
    
  3. Add a promotion to your job. This promotion will acquire the artifacts from the build being promoted, and do whatever needs to be done. This is where the Promoted Builds documentation will lead you astray. The Copy Artifacts plugin it recommends simply does not work, don’t waste your time trying to use it. Instead to acquire the artifacts:

    directory 'promoted'
       
    desc "Acquires the promoted artifacts to be released"
    task :files => 'promoted' do
      artifacts_url = "http://localhost:8080/job/#{ENV['PROMOTED_JOB_NAME']}/#{ENV['PROMOTED_NUMBER']}/artifact/artifacts"
    
      cd 'promoted' do
        sh "curl -O '#{artifacts_url}/iOSApp.ipa'"
      end
    end
    

    The only trick is to use those two environment variables PROMOTED_JOB_NAME and PROMOTED_NUMBER to build the URL to the artifacts.

  4. Once the artifacts have been copied locally, do whatever makes sense for promotion. In our case we copy the ipa to a web server so that it can be over-the-air installed to provisioned iPhones.

And that’s really all there is to it. The keys are don’t waste your time with Copy Artifacts, and build the URL to the artifacts using those environment variables.

You’re welcome, Future-Giles.