0
votes

I have created an utility (java jar-file) to generate a file upon the building process. And placed it into /tools folder in my source code root folder.

In azure-pipelines I am using this approach to run this jar-file upon building the project (Xamarin project).

  - task: CmdLine@2
    inputs:
      script: "java -jar $(build.SourcesDirectory)/tools/version2image.jar $(fullVersionText) $(androidVersionFileLocation)"

The task launched ok, but in the logs I get the following:

2020-08-17T14:48:45.4688112Z java -jar D:\a\1\s/tools/version2image.jar 1.0.0.123 'D:\a\1\s/XamarinProject/XamarinProject.Android/Resources/drawable/version.png'
2020-08-17T14:48:45.5231861Z ========================== Starting Command Output ===========================
2020-08-17T14:48:45.5731945Z ##[command]"C:\windows\system32\cmd.exe" /D /E:ON /V:OFF /S /C "CALL "D:\a\_temp\d5706f7c-43cd-4d50-8f17-98a6ae0a3391.cmd""
2020-08-17T14:48:46.8000947Z Version 2 Image Utility. version 1.0
2020-08-17T14:48:46.8001744Z 
2020-08-17T14:48:46.8002367Z 
2020-08-17T14:48:46.8003059Z Usage:
2020-08-17T14:48:46.8004115Z 
2020-08-17T14:48:46.8004468Z java -jar version2image.jar version_string output_file_location
2020-08-17T14:48:46.8004769Z 
2020-08-17T14:48:46.8005096Z Example:
2020-08-17T14:48:46.8005464Z 
2020-08-17T14:48:46.8005739Z java -jar version2image.jar 1.0.0.121 c:/myproject/images/version.png
2020-08-17T14:48:46.8005961Z 
2020-08-17T14:48:46.8507661Z ##[section]Finishing: CmdLine

In other words Azure does not pass parameters properly to the jar file. My application thinks that it launched without parameters.

But when I run this utility locally on my computer it works ok.

If it helps, in the java utility I get command line parameters like that:

 final int correctParamsCount = 2;
 if (args.length != correctParamsCount) {
   System.out.println("Usage:\n\njava -jar version2image.jar <version_string> <output_file_location>\n");
   System.out.println("Example:\n\njava -jar version2image.jar 1.0.0.121 c:/myproject/images/version.png\n");
    System.exit(0);
  }

  final String versionNumber = args[0];
  final String outputFilePath = args[1];

How can I fix this issue?

1
Quote the parameters, you args are probably split differently than you expect because of whitespace: script: 'java -jar $(build.SourcesDirectory)/tools/version2image.jar "$(fullVersionText)" "$(androidVersionFileLocation)"'riQQ
@riQQ thank you. I will check and report here.Rafael
@riQQ Thank you, you headed me to the right direction. I used quotes upon specifying paths in variable, but should not do that and use double quotes for the parameters itself. Thank you.Rafael

1 Answers

1
votes

To resolve this issue (thanks to @riQQ) I should update AndroidVersionFileLocation variable, and remove single quote symbols from the path.

And add double quotes to the utility command call:

It should look like this:

script: 'java -jar $(build.SourcesDirectory)/tools/version2image.jar "$(fullVersionText)" "$(androidVersionFileLocation)"'

instead of this:

script: "java -jar $(build.SourcesDirectory)/tools/version2image.jar $(fullVersionText) $(androidVersionFileLocation)"