4

in an Azure DevOps build pipeline, I would like to run a MsBuild task in an Azure hosted agent and a sonar analysis task in a self-hosted agent.

I understand that I need to pass artifacts from a job to another. I try to use Publish and Download pipeline artifact tasks for this purpose.

  1. First, I prepare SonarQube analysis on a self-hosted agent
  2. then I publish the .sonarqube folder
  3. On a Microsoft hosted agent I download the previously published SonarQube metadata to the job
  4. I run MsBuild and test tasks
  5. I publish test results
  6. Back on the self-hosted agent I download SonarQube metadata and test results
  7. I run SonarQube analysis

The following error message shows during the SonarQube analysis task execution.

##[error][SQ] The 'Prepare Analysis Configuration' task was not executed prior to this task

Here is how I proceed

On Self-hosted agent job "PrepareSonarqube"

  • Prepare Sonarqube analysis

Prepare Sonarqube analysis (on self-hosted agent job)

  • Publish pipeline artifact $(Pipeline.Workspace)/.sonarqube folder

Publish pipeline artifact <code>$(Pipeline.Workspace)/.sonarqube</code> folder (on self-hosted agent job)

On Microsoft hosted agent job "Build"

  • Msbuild and test tasks

Msbuild and test tasks (on Microsoft hosted agent job)

  • Publish pipeline artifact "TestResults" folder

Publish pipeline artifact TestResults folder (on Microsoft hosted agent job)

On self-hosted agent job "SonarQube Analysis"

  • Download pipeline artifact ".sonarqube" folder

Download pipeline artifact .sonarqube (on self-hosted agent job)

  • Download pipeline artifact "TestResults"

Download pipeline artifact TestResults (on self-hosted agent job)

Marc Bouvier
  • 642
  • 1
  • 11
  • 27
  • Be aware that the content of the environment variables also play an important role during a build – Jeroen Heier Sep 15 '19 at 07:54
  • You are right, I didn't think about it yet. I will dig in this direction. Thank you. – Marc Bouvier Sep 15 '19 at 15:22
  • Agree with Jeroen, in addition, you need also pay attention to the agent you used. The hosted agent could not access the file path which in private agent. Since after the hosted agent used, the VM image will be recovered, why not sync the private agent use among these three agent? – Mengdi Liang Sep 16 '19 at 03:19
  • Hi, I am not sure to understand exactly what you mean by «why not sync the private agent use among these three agent?». To add more context, the sonarqube instance I use is on a domain that cannot be accessed by Azure (let's say https://sonarqube.myorg.net). "myorg.net" being resolved by a private dns. That is why I use a self hosted agent (it can see "myorg.net domains). The reason I don't do all tasks on the same self hosted agent is that the VM I use to run agents is behind corporate proxy. It is very hard for me to install SDKs and to download tooling used during jobs run on this machine. – Marc Bouvier Sep 16 '19 at 12:29
  • Maybe I should focus on creating that complete VM that can run the all the tasks anyway: "Prepare analysis on sonarqube", "Build MsBuild solution", "Run code analysis" instead of trying to run sonarqube and build tasks on different agents? – Marc Bouvier Sep 16 '19 at 12:32
  • I found out that the "Prepare" task does create env variables SONARQUBE_SCANNER_MODE=MSBuild`, `SONARQUBE_SCANNER_MSBUILD_EXE=D:\Agents\agent-001\_work\_tasks\SonarQubePrepare_15b84ca1-b62f-4a2a-a403-89b77a063157\4.8.0\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe`, `SONARQUBE_SCANNER_PARAMS={"sonar.host.url":"https://sonarqube-dev.myorg.net/","sonar.login":***,"sonar.projectKey":"my-project","sonar.projectName":"My project","sonar.projectVersion":"1.0","sonar.scanner.metadataFilePath":"D:\\Agents\\agent-001\\_work\\_temp\\sonar\\20190916.4\\6x8\\report-task.txt"}` – Marc Bouvier Sep 16 '19 at 13:08
  • 1
    @MarcBouvier, sorry for did not have notification about your comments. Response for your second command, yes, I think you'd better finish all of these work in one agent. But also, I understand what you said, the sonarqube instance could not be accessed by hosted agent since it is locally. So, could you try with execute all in one agent? If need any help, just free to share here. I will help you. – Mengdi Liang Sep 17 '19 at 14:58

0 Answers0