/build/static/layout/Breadcrumb_cap_w.png

How can I trap warnings/errors when I try to build Nuget, Grunt, and Bower Packages from a TFS Build, PowerShell Script?

Hi all,

Here is the situation overview.  We have a pre-build script that gets needed packages in place for MSBuild during our TFS build.  The packages are created automatically when building through Visual Studio (2015), but apparently this is not done during compile using MSBuild.  So, we came up with the script approach.

It is serving us fairly well, but the problem is that if warnings appear, they are sent back to the overall build, I guess, as a script error, bad exit code so the overall build process is seen as partially successful.

First off, here is the script code that carries out the operations...

&"C:\Program Files\Microsoft Team Foundation Server 14.0\Tools\Nuget.exe" restore  $source\MyAppNet\MyAppWeb\MyAppWeb.sln

bower install -s

cmd.exe /c npm install
cmd.exe /c grunt concat
cmd.exe /c grunt less

And now an example of warnings...

npm WARN deprecated lodash@2.4.2: lodash@<3.0.0   is no longer maintained. Upgrade to lodash@^3.0.0.

npm WARN deprecated lodash@0.9.2: lodash@<3.0.0   is no longer maintained. Upgrade to lodash@^3.0.0.

npm WARN deprecated lodash@1.0.2: lodash@<3.0.0   is no longer maintained. Upgrade to lodash@^3.0.0.

In this particular example, the warnings are coming during the grunt operations.

I have tried directing output of the above commands to a file, but the contents do not contain these warnings.  My hope is that I can find a way to see these warnings/errors in the PowerShell script and maybe send the results to a hashing function of some sort.  Based on what I find, I'll set the script Exit code and handle that by modifying my XAML TFS Build Template to act accordingly.

So, the first part of my task, if possible is to notice WARN with the script.  Does anyone know how I can capture messages such as these in my PowerShell script?  Based on what they are the script's exit code will determine whether or not to terminate the entire build process.

I hope someone can help!

 

Thanks in advance!!

 


1 Comment   [ + ] Show comment
  • Still haven't found a solution, but I haven't been spending much time on it. However, I'm back to it so I hope to be able to report something soon. - Superfreak3 8 years ago

Answers (3)

Posted by: Pressanykey 8 years ago
Red Belt
0
Hi,
You would probably need to provide more information on exactly what the individual "mini-apps" do, and the return codes that they give to provide a real answer. But generally, power shell does / can use the "classic" try / catch exception handling, as well as be able to evaluate return codes so that you can react accordingly. As for capturing messages coming from a call, this can also be evaluated, using, for example, regular expressions and also reacting accordingly.

Phil

Comments:
  • By the mini-apps, do you mean what bower install, npm install, grunt concat, grunt less, and the Nuget restore actually do?

    I've tried the try catch, but that doesn't seem to trap what I need either.

    I've been struggling with this for weeks. My hope is that there is some way to have MSBuild run these commands autmoatically, maybe setting this up through Visual Studio. - Superfreak3 8 years ago
    • Might I suggest a look at (perhaps) a few Powershell tutorials? As you are using external tools in your existing script that are from the *nix world, I think that you should be able to pick it up fairly easily. - Pressanykey 8 years ago
      • I'm a newb to PowerShell as well, that's for sure so any tutorials would be beneficial.

        I'm not sure what you mean by "*nix world", but would you have links to any tutorials pertaining to this? - Superfreak3 8 years ago
Posted by: Pressanykey 8 years ago
Red Belt
0
Hi Superfreak,
*nix = Linux / Unix, thought that was where the grunt* commands were coming from...
I would recommend the following book, PowerShell in a month of lunches , I used this in a crash-course for Power shell beginners and it went well.
I suppose if we leave this here, perhaps someone else has some more / other suggestions.

Cheers
Phil

Comments:
  • Ah, that's why I was thrown. This is all windows based. I had that book on my radar so I think I'll pick it up. Hopefully someone out there has some direct experience with my issue as well. - Superfreak3 8 years ago
Posted by: Superfreak3 7 years ago
2nd Degree Black Belt
0
Got this from npm support and it worked perfectly.  Had to set the log level...

"If you run npm config list you should see a shortlistof your config details. Then, you can run npm config setloglevel error and to confirm, run npm config list again to see that yourloglevel has changed."

Following this, the CI builds are seen as fully successful!!
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ