Azure DevOps Pipelines build using Xcode CLI command, xcodebuild, failing. Cannot open content.xcworkspacedata file - xcode

I am attempting to trigger an Xcode build using Azure Pipelines. Pipelines essentially uses Xcode BuildTools commands to create the build. I am receiving the following error where I've inserted Project and ProjectPath to replace:
xcodebuild: error: Unable to read project ProjectName.xcodeproj' from folder 'ProjectPath'. Reason: Could not open workspace file at ProjectPath.xcodeproj/project.xcworkspace/contents.xcworkspacedata
Strange thing is that if I run my build command directly on the build server, from the build server's CLI, there is no issue and the build succeeds. However, when I try via Pipelines it says that this particular file, contents.xcworkspacedata, can't be opened.

Related

Why can't 'dotnet lambda deploy-function' pull a package from an Azure DevOps artifact feed?

I'm using the AWS deploy lambda task within Azure DevOps. Within the lambda function that gets deployed, it's setup to pull a package from an artifact feed within the same Azure DevOps repo/installation.
If I run NuGet restore in a previous step to the deploy then the package can be accessed fine however when it then hits the AWS Lambda .NET Core Deployment step it gets a 401 when trying to read from the same feed.
Does anyone know how I could configure the lambda release step to successfully read from a custom feed?
The specific error is:
Response status code does not indicate success: 401
I am having the same issue but hopefully I can offer a bit of a new angle on it.
Rather than using the AWS deploy lambda run we are packaging our lambdas and pushing them to S3 to allow CloudFormation to deploy them. This uses the AWS dotnet toolkit to construct the deployment package (which is what aws deploy lambda is doing in the background). The powershell step that performs this then looks like:
dotnet lambda package
The resultant package will then typically be generated inside of the bin/release folder beneath your project.
What this then lets you do is add the parameters --msbuild-parameters "--no-restore" to the packaging process which will not trigger the automatic restore step. Inside of Azure DevOps Build Pipelines you can set a build step before it to restore for all solutions or csproj files which will authenticate against your feed automatically. We also set the version number of the asssemblies and I wanted to get rid of an annoying warning so our current version of this call looks like:
dotnet lambda package ("/p:Version=" + $VersionNumber) "/p:PreserveCompilationContext=false" --msbuild-parameters "--no-restore"
The problem that I am now running into is that passing in the msbuild-parameters seems to set the framework to target red hat linux (rhel.7.2-x64) resulting in the following error:
publish: C:\Program Files\dotnet\sdk\2.1.500\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(198,5): error NETSDK1047: Assets file 'C:\Agent\_work\1\s\Kiosk.Microservice.User.Lambda.Command\obj\project.assets.json' doesn't have a target for '.NETCoreApp,Version=v2.0/rhel.7.2-x64'. Ensure that restore has run and that you have included 'netcoreapp2.0' in the TargetFrameworks for your project. You may also need to include 'rhel.7.2-x64' in your project's RuntimeIdentifiers. [C:\Agent\_work\1\s\Kiosk.Microservice.User.Lambda.Command\Kiosk.Microservice.User.Lambda.Command.csproj]
I very explicitly want it to build for dotnetcore2.0 so I don't actually want to build for red hat linux.
This is where I am currently stuck as if I don't use the flag to stop the unauthenticated nuget restore step, I get the unauthorized error and I can't seem to pass dotnet.exe my feed credentials. If I do use the flag it builds for red hat Linux for no coherent reason. Hopefully this gets you at least a little farther!
Update: I now have my stuff working. I went and found the dotnet cli wrapper that dotnet lambda publish is actually using in the git repository for the toolset and duplicated its steps without the middleman. Because the msbuild-parameters flag was no longer used it didn't try to build it in red hat linux. I did also have to create the zip file afterwards as well but that is fairly trivial. The following is the powershell that is generating the new packages without the aws dotnet toolset:
# Run the build that will generate the proper files
dotnet publish --no-restore -f netcoreapp2.0 -c Release
# Create the path to the zip file
$PathToZip = $PathToCSProj + "\bin\Release\netcoreapp2.0\publish"
# Create the zip file
Compress-Archive -Path $PathToZip -DestinationPath ($PathToZip + $csproj[0].Name.trim(".csproj") + ".zip")
I hope this helps!

Xcode Generate Code Coverage Report fails with Error : Error Domain=IDEFoundationErrorDomain Code=14 "Failed to merge raw profiles in directory

I am unable to generate the code coverage data when the the workspace is built with custom XCODE_CONFIGURATION_BUILD_DIR.
We run the xcodebuild commands to build the workspace with a XCODE_CONFIGURATION_BUILD_DIR, so that multiple jenkins CI jobs won't overwrite the build output of other jobs which are also running concurrently.
When we run the tests for a build generated this way and try to get the code coverage report, the command fails with the below error.
jenkins$ xcrun xccov view *.xccovreport
Errors:
Error Domain=IDEFoundationErrorDomain Code=14 "Failed to merge raw profiles in directory /Users/jenkins/Library/Developer/Xcode/DerivedData/XXXXXX-buggtqumttnpjvejnbfhulhqcvno/Build/ProfileData/bff950eda0f75b2dbadb3ce08510474b4667ac82 to destination /Users/jenkins/Library/Developer/Xcode/DerivedData/XXXXXX-buggtqumttnpjvejnbfhulhqcvno/Build/ProfileData/bff950eda0f75b2dbadb3ce08510474b4667ac82/Coverage.profdata: No profile data files were written to '/Users/jenkins/Library/Developer/Xcode/DerivedData/XXXXXX-buggtqumttnpjvejnbfhulhqcvno/Build/ProfileData/bff950eda0f75b2dbadb3ce08510474b4667ac82'" UserInfo={NSLocalizedDescription=Failed to merge raw profiles in directory /Users/jenkins/Library/Developer/Xcode/DerivedData/XXXXXX-buggtqumttnpjvejnbfhulhqcvno/Build/ProfileData/bff950eda0f75b2dbadb3ce08510474b4667ac82 to destination /Users/jenkins/Library/Developer/Xcode/DerivedData/XXXXXX-buggtqumttnpjvejnbfhulhqcvno/Build/ProfileData/bff950eda0f75b2dbadb3ce08510474b4667ac82/Coverage.profdata: No profile data files were written to '/Users/jenkins/Library/Developer/Xcode/DerivedData/XXXXXX-buggtqumttnpjvejnbfhulhqcvno/Build/ProfileData/bff950eda0f75b2dbadb3ce08510474b4667ac82'}
Version/Build:
Version 10.1 (10B61)
Found this thread on Github
The issue was: generating coverage for a Static Library fails, but not for a Dynamic Library.
So check if it works, changing on pbxproj:
- MACH_O_TYPE = staticlib;
+ MACH_O_TYPE = mh_dylib;
And it really generated coverage successfully on my sample framework.
The solution which worked for me was, I have changed the Mach-O-Type from Executable to Static Library.
With the option Dynamic Library also, the coverage report was generating but the build was failing.
Another option was to set the test target as Static Library and Main Target as Executable. Build Succeeded and able to see the coverage for multiple targets.
Xcode Version : 13.4

Deploying to Octopus from Teamcity with .Net Core not creating .zip

I am doing the following steps:
dotnet restore
dotnet publish
octopusDeploy: Push packages
The second step creates a 'published-app' folder and the third step is meant to take that and create a .zip file and send it to the Octopus server.
The third step is connecting to the Octopus server but gives the error:
Running command: octo.exe push --server http://server.com/ --apikey SECRET
Pushing packages to Octopus server
Please specify a package to push
I am following this https://stackoverflow.com/a/38927027 so my third step has:
%teamcity.build.workingDir%/published-app/**/* => App.zip
Any ideas why the zip file is not being created?
Not sure if you ever got this working for yourself, however just in case it helps anyone we recently came across the same issue deploying an AspNetCore 2.0 web application running on net471 being built by TeamCity 2017.1.4 (build 47070).
After some tinkering I noticed that the "OctopusDeploy: Create and Push Packages" build step ran at our git checkout root directory, so I ending up having to use the following values for the "Package path patterns"
%ProjectDirectory%/published-app/**/* => %ProjectName%.%GitVersion.NuGetVersion%.zip
NB: %ProjectDirectory%, %ProjectName% and %GitVersion.NuGetVersion% are build parameters we have manually defined elsewhere in the build process that TeamCity can replace. %ProjectDirectory% is simply the application's source directory relative to the root of the git checkout i.e. WebApplication1 so the full path would be <full checkout path>/WebApplication1
Another gotcha that we experienced was that at the time of writing the combination of TeamCity and octo.exe (from Octopus.TeamCity v4.15.10) didn't like creating nupkg files, so make sure you try to produce a ".zip" file. In the error instances we would receive the following error:
Error from Octo.exe: Cannot run program "C:\BuildAgent\temp\buildTmp\octo-temp\3.0\octo.exe" (in directory "C:\BuildAgent\work\4e62985fa616fa1f"): CreateProcess error=206, The filename or extension is too long

Trying to compile an XCode project with a workspace on Jenkins slave

I got a Jenkins slave building single xcode projects, working perfectly.
However, I got a project with a workspace where some 3rd party files are setup in the root of the workspace with a gitmodule then imported in to the project as described here.
When Jenkins compiles and reaches AppDelegate.h it throws and error when trying to import a file from the library.
fatal error: 'RestKit/Restkit.h' file not found #import <RestKit/Restkit.h>
I got the project compiling by pointing to the workspace. However it now fails when reaches the packaging stage. I don't see the build directory created in the workspace.
** BUILD SUCCEEDED **
Cannot remove *.ipa files from a non-existing directory:
/Users/leon/Work/projects/wearehive/flatstr/build/Flatstr/dev/jenkins/workspace/Snug-debuOLD/build/Debug-iphoneos
Packaging IPA
FATAL: null
java.lang.NullPointerException
at au.com.rayh.XCodeBuilder.perform(XCodeBuilder.java:421)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:19)
at hudson.model.AbstractBuild$AbstractRunner.perform(AbstractBuild.java:705)
at hudson.model.Build$RunnerImpl.build(Build.java:178)
at hudson.model.Build$RunnerImpl.doRun(Build.java:139)
at hudson.model.AbstractBuild$AbstractRunner.run(AbstractBuild.java:475)
at hudson.model.Run.run(Run.java:1434)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
at hudson.model.ResourceController.execute(ResourceController.java:88)
at hudson.model.Executor.run(Executor.java:239)
Your Project=>build settings=>Header Search Paths, add follow path:
"$(SOURCE_ROOT)/RestKit/Build/Headers"
Be sure checked box in front of them.
I use xcode plugin and use this for SYMROOT value instead of space fixes the problem.
${workspace}/build/[app name]/Build/Products

ld: library not found for -lLIBRARY_NAME, only when trying to build using jenkins

I have a project that when built from my machine everything runs smoothly. However, when I push my changes and try to generate the build using jenkins, I'm getting the library not found error message.
This is weird because if I login into the jenkins server and I try to do a manual build, everything works as expected, perfect. It's only when I build from withing jenkins that my build is failing.
I'm assuming LIBRARY_NAME as the name of whatever library, in my case is an internal static library.
Any suggestions?
EDIT:
I've setup: Library Search Headers, Other Linker Flags, Target Dependencies, Proper Architectures
I wrestled with this for three weeks until I accidentally stumbled onto this with the help of a coworker. Basically, you must be sure that the path structure created in your repository is replicated in the .jenkins workspace. To do this just be sure that in your project/job configuration in jenkins the Source Code Management > Subversion > Repository URL field must be at the same level as specified in jenkins in your script or Build > Execute Shell > Command field. So here are my settings as an example:
above Jenkins URL = https://myDuncwa.local/duncwa-repo
above Jenkins Build = "cd $WORKSPACE/mobileapps/projects/PictureBoard/trunk/PictureBoard" and line 2 "xcodebuild -project PictureBoard.xcodeproj" no quotes.
above Subversion URL repository = https://myDuncwa.local/duncwa-repo
This will cause the directory structure mobileapps/projects/PictureBoard in my repository to replicated in the .jenkins/jobs/PictureBoard/workspace/mobileapps/projects/PictureBoard directory that is created automatically by jenkins. Note: 1) This will copy the entire repository so be prepared to change this later and 2) .jenkins is a hidden directory created by the install in the installing user's home directory or "~/"

Resources