0

I am trying to create a pipeline using Concourse CI using Maven. The pipeline should:

  • Get the code from git.
  • Build and run test using maven.
  • the project generates html report in target folder

above steps are executing properly. The question how to access the output i.e target folder generated by the maven project.

I am not able to access the generated folder and copy to the required folder for later usage.

File pipeline.yml:

resources:
- name: branch-master
  type: git
  source:
    uri: {{git-url}}
    branch: master

jobs: 
- name: MavenJob
  serial: true
  plan:
  - get: branch-master
    trigger: true
  - task: mvn-test
    privileged: true
    file: branch-dev/AppDemo/test.yml

File test.yml:

platform: linux

image_resource:
  type: docker-image
  source:
    repository: maven
    tag: latest

inputs:
  - name: branch-master
outputs:
  - name: mvn-output

run:
  path: "mvn"
  args: ["-f", "branch-master/AppDemo/pom.xml", "test"]

Please some body help me.

Thanks in advance.

Anji R
  • 843
  • 3
  • 16
  • 23
  • did you try hijacking into concourse container to see whats happening there? – Random Guy Mar 25 '20 at 19:58
  • in concourse console it is showing Surefire report directory: /tmp/build/91460b75/branch-master/AppDemo/target/surefire-reports, but unable to find the tmp folder in container. when i ran the job for first time it downloaded image with some name and then it not downloading, where it will be stored in main container and unable to find the path , i am new to concourse still learning can you please guide me – Anji R Mar 26 '20 at 02:25

1 Answers1

0

For sake of simplicity and unambiguity I renamed your git repo to project. Let's assume it contains concourse's yamls. And there is a directory AppDemo with java-maven app

project/pipeline.yml:

resources:
- name: project
  type: git
  source:
    uri: {{git-url}}
    branch: master

jobs: 
- name: MavenJob
  serial: true
  plan:
  - get: project
    trigger: true
  - task: mvn-test
    privileged: true
    file: project/test.yml

the job above should locate and trigger the test.yml task

project/test.yml:

platform: linux

image_resource:
  type: docker-image
  source:
    repository: maven   # let's hope bin/bash is available there. if no, use sh
    tag: latest

inputs:
  - name: project   # project is your git-repo. all paths are relative to it's location
outputs:
  - name: mvn-output

run:
  path: /bin/bash
  args: 
    - project/test-script.sh:

project/test-script.sh:

_ROOT=$(pwd)
echo "starting test-script from directory: $ROOT"

cd _ROOT/AppDemo
mvn test

if you want to pass outputs of maven job somewhere further, then you should just copy all those files into mvn-output directory later in the script.

I would also recommend using this bash-script as wrapper rather than raw "maven call" - it's more convenient for debugging the whole process as you can, e.g. echo'ing paths.

in case of any error, if container still alive, try hijacking into it to see what has actually happened there and where files are located:

fly -t <target> hijack -u <url-of-failed-job-from-your-browser>

hope this helps

Random Guy
  • 1,095
  • 16
  • 29
  • Hi Random Guy, Thanks for your valuable inputs. i am able to run test and copy the target folder to maven-output folder. i was able to hijack the into container and validate it. but each time i run the build , it is taking more time to download the dependcies, is there a way to store then some where to minimize the time? once again then you – Anji R Mar 28 '20 at 10:27
  • @AnjiR Probably the easiest way to do so - is to use concourse's caching out-of-the-box. You can just add `caches: - path: .m2/` to task's test.yml. Note that values are cached on particular concourse worker. There is a [question dedicated to concourse caching](https://stackoverflow.com/questions/40736296/how-to-cache-maven-repository-between-builds) – Random Guy Mar 28 '20 at 15:19