5

I have a BitBucket Pipeline that installs a bunch of Perl modules using cpanm. One of them fails and this is the snippet I can see in the log:

Fetching http://www.cpan.org/authors/id/P/PE/PETDANCE/ack-v3.0.2.tar.gz ... OK
Configuring ack-v3.0.2 ... OK
==> Found dependencies: File::Next
--> Working on File::Next
Fetching http://www.cpan.org/authors/id/P/PE/PETDANCE/File-Next-1.16.tar.gz ... OK
Configuring File-Next-1.16 ... OK
Building and testing File-Next-1.16 ... OK
Successfully installed File-Next-1.16
! Installing App::Ack failed. See /root/.cpanm/work/1562605191.55/build.log for details. Retry with --force to force install it.
! Installing the dependencies failed: Module 'App::Ack' is not installed
! Bailing out the installation for ..
Building and testing ack-v3.0.2 ... FAIL

How could I access the build.log that was created by the installation process?

szabgab
  • 6,202
  • 11
  • 50
  • 64
  • `cat /root/.cpanm/work/1562605191.55/build.log` – ikegami Jul 23 '19 at 18:05
  • 1
    That would be fine if I had access to the machine after it finished running, but AFAIK I don't have. – szabgab Jul 23 '19 at 18:10
  • wut. How and why are you installing a module on a machine you can't use?! – ikegami Jul 23 '19 at 18:12
  • That said, you could use `cpan` instead of `cpanm`. `cpan` doesn't hide useful information like `cpanm` does. – ikegami Jul 23 '19 at 18:14
  • It's a CI system. It spins up a Docker image, installs stuff, runs the tests, destroys the instance. I juts found they have added an option to run a script after failure. I'll check if that can be used to display the log files. – szabgab Jul 23 '19 at 18:19
  • I suspect the name of the file changes each time. But since it's a fresh instance, `/root/.cpanm/work/*/build.log` should only match relevant files. – ikegami Jul 23 '19 at 18:20

1 Answers1

3

Apparently recently Bitbucket added a feature called "after-script" so I could add the following and that would print the content of the log files.

       after-script:
          - ls -1 /root/.cpanm/work/*/build.log | xargs cat

or maybe even this:

       after-script:
          - cat /root/.cpanm/work/*/build.log

and the following, I think, will only show the content of the log files if the build failed:

       after-script:
          - $BITBUCKET_EXIT_CODE && cat /root/.cpanm/work/*/build.log

Read more here: https://bitbucket.org/blog/after-scripts-now-available-for-bitbucket-pipelines

szabgab
  • 6,202
  • 11
  • 50
  • 64
  • I don't think you need the `-1` on your `ls` command since `ls` always lists one file per line when STDOUT is not connected to a tty (i.e.: if it is connected to a pipe or file). Also I'm curious what advantage the `ls | xargs cat` construct gives you over just `cat `. – Grant McLean Jul 23 '19 at 21:28
  • @Grant McLean, The `xargs` version will help if the list is long enough to hit the command line length limits, but that's not likely to happen in the scenario the OP gave – ikegami Jul 24 '19 at 01:21
  • @GrantMcLean probably just overengineering. Now added that solution as well. – szabgab Jul 24 '19 at 02:43