23

I'm trying to setup a script to increment the build number of my Xcode project. I make an API call to get the current build number, then I wanted to increment it and apply that new number as an environment variable so that the Xcode Plugin can use it.

I have the EnvInject plugin installed but I don't know how to get the var from my shell script into a Environment Variable.

APP_BUILD_NUMBER=$(curl --request GET 'https://api.domain.com/api/GetBuildNumber')
APP_BUILD_NUMBER=$((APP_BUILD_NUMBER +1))

This sets APP_BUILD_NUMBER to the value I need, but how do I assign this to a environment variable so I can access it later on in my job?

ChickensDontClap
  • 1,871
  • 4
  • 22
  • 39

2 Answers2

47

Add a build step to execute shell - in there determine APP_BUILD_NUMBER and output to file, e.g.

APP_BUILD_NUMBER=$(curl --request GET 'https://api.domain.com/api/GetBuildNumber')
APP_BUILD_NUMBER=$((APP_BUILD_NUMBER +1))
echo APP_BUILD_NUMBER=$APP_BUILD_NUMBER > build.properties

then add build step Inject environment variables and set there Properties File Path to $WORKSPACE/build.properties

after that $APP_BUILD_NUMBER is accessible in all build steps after as environment variable; e.g. in Xcode build step

MrsTang
  • 3,119
  • 1
  • 19
  • 24
  • 1
    Please note that the https://wiki.jenkins-ci.org/display/JENKINS/EnvInject+Plugin plugin doesn't support Pipeline syntax. – mattes Jun 03 '17 at 01:30
2

These are also worth considering

Federico
  • 1,636
  • 2
  • 22
  • 24