I have tried a few things, but I can't get the variables to stick, probably because I am not used to writing Scripts.
The documentation from Appcenter : https://learn.microsoft.com/en-us/appcenter/build/custom/variables/
It says I can only access the environment variables from app center in the build script..
I have tried creating a Run Script from Build phases, but no variables is saved no matter what. How do I save an environment variable ? I have tried, export ENVIRONMENT_TEST="abc", but I cant see it afterwards using
let environments = ProcessInfo.processInfo.environment["ENVIRONMENT_TEST"]
I found a similar issue: Using Microsoft App Center environment variables in iOS
here the solution is to save the environment variable $ENVIRONMENT_VARIBLE to a file and read from it later. So now im trying to save to a new plist file. This works locally, but not from a device. I believe its because the path is different. I use:
plutil -replace somekey -string somevalue1 ${SOURCE_ROOT}/AppName/AppcenterValues.plist
Any ideas for this ?
the predefined variables are different, instead of SOURCE_ROOT use APPCENTER_SOURCE_DIRECTORY. You script will end up something like this:
plutil -replace somekey -string somevalue1 $APPCENTER_SOURCE_DIRECTORY/AppName/AppcenterValues.plist
You can find more examples on the official AppCenter github repository in following link:
https://github.com/microsoft/appcenter/blob/master/sample-build-scripts/react-native/version-name/appcenter-pre-build.sh
Related
Im trying to build my flutter app for iOS it has a google maps key that I want to protect and not check in to source control it needs to be buildable from azure, to achieve this I'm storing my maps key as a secret variable in azure and as a system environment variable locally, I'm using Sourcery https://github.com/krzysztofzablocki/Sourcery to generate a class for me that contains this key, it all works but only the second time I build, the first build always fails.
So I'm building using this command
flutter build ios --flavor dev --verbose
Which the first run will give me the error
error: Build input file cannot be found:
'/Users/martin/xxx/xxx/xxx/ios/Runner/Credentials.generated.swift' (in target
'Runner'
Then issuing the same command again
** BUILD SUCCEEDED **
this is my run script its called before compile sources and after the flutter run script
this calls my script which calls another script to export the map api key and runs sourcery command using a .yml file as its config heres the script, (it also does some logging)
#!/bin/bash
echo "Generate Credentials Code"
CREDENTIALS_DIR="$SRCROOT/credentials"
# Set credentials if local script for adding environment variables exist
if [ -f "$CREDENTIALS_DIR/add_credentials_to_env.sh" ]; then
echo "Add credentials to environement"
source "$CREDENTIALS_DIR/add_credentials_to_env.sh"
echo "finished running add_credentials_to_env.sh"
fi
echo "RUN SOURCERY"
$SRCROOT/Pods/Sourcery/bin/sourcery --config "$SRCROOT/config.yml"
echo "FINISHED RUNNING SOURCERY"
for file in "$SRCROOT/Runner"/*; do
echo "$file"
done
and here is my config file
sources:
- .
project:
file: Runner.xcodeproj
target:
name: Runner
module: Runner
templates:
- credentials/Credentials.stencil
output:
path: ./Runner/
link:
project: Runner.xcodeproj
target: Runner
args:
mapsApiKey: ${MAPS_API_KEY_IOS}
this generates my class correctly on the first build and seems to be added correctly to the target (edited out my key) but the app will only compile if I run the build command again.
// Generated using Sourcery 1.4.2 — https://github.com/krzysztofzablocki/Sourcery
// DO NOT EDIT
public struct Credentials {
let mapsApiKey: String
}
public let credentials = Credentials(mapsApiKey:
"xxxxxxxxxxMY_KEYxxxxxxxxxxx")
Any ideas?
xcode 12.5 m1 macbook pro, swift 5
Looks like you generate the file too late. I'll suggest move your script to Aggregate and add it as a dependency to your target
Add Aggregate
Move your script to 'Run script' section
Add 'PreBuildScriptsRunner' as a dependency to your application target, make sure 'Dependencies' section on top of all other sections
Manually setting environment variables is an annoying thing developers would have to do on their own machines, and there are nicer/ more common ways of setting up private keys. After a few years of using environment variables/ bash, it still causes issues which are not easily detectable. You may want to automate/ document it, but then you have to consider developers using zsh, fish vs. bash? Also, I try to avoid using Xcode build phases where possible.
Solution? (This is what I have)
Why don't you use your CI (Azure pipeline?, I use Github workflows) to write a Xcode build configuration file (not a Swift file). The sensitive keys could be in a file Secrets.xcconfig, which is added to your Xcode as a build configuration. Then, in your Info.plist of your application, and your code can load them.
Create a file, Secrets.xcconfig:
SECRET_API_KEY = 12312rfiwhvde.wvascafsf.df325
Add it to your Xcode project, and then to the project's build configuration:
Add Secrets.xcconfig to your .gitignore
Make sure to git ignore the file before committing it to the repo. You can also keep an Example.Secrets.xcconfig which users can use. In the readme, tell users to run cp Example.Secrets.xcconfig Secrets.xcconfig and then to update values in it. Now you can clearly see what keys the application is using (its clearly in the directory). As a bonus, you can add this file the Xcode project, so that when the file is missing, it shows up in red (indicating to the user they really should acquire this file somehow):
In Info.plist, reference the variable:
<dict>
<key>SECRET_API_KEY</key>
<string>$(SECRET_API_KEY)</string>
</dict>
In your code, load the variable that was stored in Info.plist:
let key = Environment.infoDictionary["SECRET_API_KEY"] as? String
In your CI/ Azure pipeline:
Run echo "SECRET_API_KEY = $SECRET_API_KEY_SAVED_IN_CONTINUOUS_INTEGRATION" >> Secrets.xcconfig
Then you can just .gitignore the file instead of setting environment variables. When you work with other developers, you just give them this file, and nothing else needs to be done to build locally.
So I have answered your question not by solving your direct problem, but giving you a more common/ canonical way of solving this problem that many developers have faced before.
I'm using a bot to archive an iOS app, and I need to get the .ipa product path in order to publish it into our distribution system.
Bot settings:
And using a script to print all env variables, non of them contains a path to the ipa file. In addition, some of the variables are pointed to directory that does not exist, i.e: XCS_OUTPUT_DIR
Here the env variable output:
XCS=1
XCS_ANALYZER_WARNING_CHANGE=-31
XCS_ANALYZER_WARNING_COUNT=0
XCS_ARCHIVE=/Library/Developer/XcodeServer/Integrations/Integration-771867708dfac45bba10a1998c118912/MyApp.xcarchive
XCS_BOT_ID=771867708dfac45bba10a1998c007d43
XCS_BOT_NAME='MyApp Distribution'
XCS_BOT_TINY_ID=DBB85BD
XCS_DERIVED_DATA_DIR=/Library/Developer/XcodeServer/Integrations/Caches/771867708dfac45bba10a1998c007d43/DerivedData
XCS_ERROR_CHANGE=-1
XCS_ERROR_COUNT=0
XCS_INTEGRATION_ID=771867708dfac45bba10a1998c118912
XCS_INTEGRATION_NUMBER=19
XCS_INTEGRATION_RESULT=warnings
XCS_INTEGRATION_TINY_ID=F7D4469
XCS_OUTPUT_DIR=/Library/Developer/XcodeServer/Integrations/Integration-771867708dfac45bba10a1998c118912
XCS_SOURCE_DIR=/Library/Developer/XcodeServer/Integrations/Caches/771867708dfac45bba10a1998c007d43/Source
XCS_TESTS_CHANGE=0
XCS_TESTS_COUNT=0
XCS_TEST_FAILURE_CHANGE=0
XCS_TEST_FAILURE_COUNT=0
XCS_WARNING_CHANGE=0
XCS_WARNING_COUNT=26
XCS_XCODEBUILD_LOG=/Library/Developer/XcodeServer/Integrations/Integration-771867708dfac45bba10a1998c118912/xcodebuild.log
XPC_FLAGS=0x0
XPC_SERVICE_NAME=com.apple.xcsbuildd
In addition to that, I was able to confirm that .ipa files are being created in another folder (<path to server>/IntegrationAssets/<integration id>/<integration number>/), but that path is not accessible from an env variable.
Any ideas?
Well, after a lot of research and testing and all, apparently there is something wrong with bots in the latest Xcode (7.2) + Server version (5.0.15) not loading the correct environment variables.
My current solution was to create the path manually based on existing env variables:
ARCHIVE_PATH="${XCS_ARCHIVE}"
ARCHIVE_NAME="${ARCHIVE_PATH##*/}"
IPA_NAME="${ARCHIVE_NAME%.*}.ipa"
IPA_PATH="${XCS_OUTPUT_DIR}/ExportedProduct/Apps/${IPA_NAME}"
Which I did based on:
Continuous integration Xcode Server after trigger $XCS_PRODUCT not set
Just a small update--In Xcode 9.4.1 at least $XCS_PRODUCT is set correctly, so you can just use that, e. g. for HockeyApp:
curl -F "status=2" -F "notify=1" -F "ipa=#${XCS_PRODUCT}" -H "X-HockeyAppToken: <token>" https://rink.hockeyapp.net/api/2/apps/upload
I would like to deploy some js files to bintray, reading the instructions on http://docs.travis-ci.com/user/deployment/bintray/ I see that the name of the version is configured in the descriptor file. I would like it to use the git-tag instead. So that to make a release I only need to push a tag without having to modify a configuration file on each release. Is this possible?
You need to use the built-in environment variables. The one that you are looking for is TRAVIS_TAG. The full list is here.
you have to generate the descriptor file as part of your build. There you can check the environment variable using e.g. python or shell.
I'm trying to run a command via QProcess but it's not working. My command is something like utility -someflag /path/to/file. utility is in the PATH, however it seems QProcess is not using this environment variable.
The command simply fails and I need to specify the full path of the utility (which I'd like to avoid).
Is there any way around this? Basically some way to make QProcess use the PATH variable?
So the problem is that it depends on how the application is started. This is on OSX but it might be similar in other platforms:
If it's a command line application and started from a terminal then it will have access to the env variables.
If it's started from Qt Creator, it will not have access to any env variable.
If it's a GUI application (.app), it will not have access to the env variables.
The solution in my case, since it is a GUI application, was to update the .app package manually. First the file Info.plist needs to be changed from this:
<key>CFBundleExecutable</key>
<string>MyApplication</string>
to this:
<key>CFBundleExecutable</key>
<string>MyApplication.sh</string>
Then, still in the app package, in Contents/MacOS, create a new file with the same name as the application, but with a .sh extension, eg. "MyApplication.sh". Then create the launcher:
#!/bin/sh
SCRIPT_DIR=$(dirname "$0")
source ~/.bash_profile
logger "$SCRIPT_DIR/MyApplication"
exec "$SCRIPT_DIR/MyApplication" $#
The source ~/.bash_profile line in particular ensures that all the environment (including PATH variable) will be set properly.
I'm running a multi-program projects using ACE TAO. I set the Environment Variables and compiled ACE_TAO environment. Then I copied the tao_cosnaming.exe to my project run directory and use a .bat to start the naming service.
The programs run well if I start them directly, but they could not get the "NameService" correctly when I invoke obj = orb->resolve_initial_references("NameService") in debug mode. (I could not run obj->_non_existent(), it throws an error).
It seemed because the Naming Service is implemented as a remote one. When I invoke obj = orb->invoke resolve_initial_references("RootPOA"), things are fine, because RootPOA is local object so obj->_non_existent() return immediately.
The .bat file is like:
cd /D %DTAX_RUN_DIR%
tao_cosnaming -ORBEndPoint iiop://%DTAX_NAME_SERVICE_HOST%
The DTAX_RUN_DIR and DTAX_NAME_SERVICE_HOST are Environment Variables. DTAX_RUN_DIR is project run directory and DTAX_NAME_SERVICE_HOST=169.254.51.81:10493
Could anybody share some ideas on what is going wrong? Thanks!
It's hard to give a definite solution with just the information you provided, but in my projects I need to pass "-c" (without the quotes) as a command argument so that I can debug it, maybe you need to do the same.
In Visual Studio in the project properties you can find the Command arguments field in Properties/Debugging.