Concourse task input folder is empty

2.2k views Asked by At

I'm experimenting with building a gradle based java app. My pipeline looks like this:

---
resources:
- name: hello-concourse-repo
  type: git
  source:
    uri: https://github.com/ractive/hello-concourse.git

jobs:
- name: gradle-build
  public: true
  plan:
  - get: hello-concourse-repo
    trigger: true
  - task: build
    file: hello-concourse-repo/ci/build.yml
  - task: find
    file: hello-concourse-repo/ci/find.yml

The build.yml looks like:

---
platform: linux

image_resource:
  type: docker-image
  source:
    repository: java
    tag: openjdk-8

inputs:
- name: hello-concourse-repo
outputs:
- name: output

run:
  path: hello-concourse-repo/ci/build.sh

caches:
- path: .gradle/

And the build.sh:

#!/bin/bash

export ROOT_FOLDER=$( pwd )
export GRADLE_USER_HOME="${ROOT_FOLDER}/.gradle"

export TERM=${TERM:-dumb}
cd hello-concourse-repo
./gradlew --no-daemon build

mkdir -p output
cp build/libs/*.jar output
cp src/main/docker/* output
ls -l output

And finally find.yml

---
platform: linux

image_resource:
  type: docker-image
  source: {repository: busybox}

inputs:
- name: output

run:
  path: ls
  args: ['-alR']

The output of ls at the end of the bash.sh script shows me that the output folder contains the expected files, but the find task only shows empty folders:

concourse ui

What am I doing wrong that the output folder that I'm using as an input in the find task is empty?

The complete example can be found here with the concourse files in the ci subfolder.

2

There are 2 answers

2
Rolo On BEST ANSWER

You need to remember some things:

  1. There is an initial working directory for your tasks, lets call it '.' (Unless you specify 'dir'). In this initial directory you will find a directory for all your inputs and outputs.

    i.e.

    ./hello-concourse-repo
    ./output
    
  2. When you declare an output, there's no need to create a folder 'output' from your script, it will be created automatically.

  3. If you navigate to a different folder in your script, you need to return to the initial working directory or use relative paths to find other folders.

Below you will find the updated script with some comments to fix the problem:

#!/bin/bash

export ROOT_FOLDER=$( pwd )
export GRADLE_USER_HOME="${ROOT_FOLDER}/.gradle"

export TERM=${TERM:-dumb}
cd hello-concourse-repo #You changed directory here, so your 'output' folder is in ../output
./gradlew --no-daemon build

# Add this line to return to the initial working directory or use ../output or $ROOT_FOLDER/output when compiling.

#mkdir -p output <- This line is not required, you already defined an output with this name

cp build/libs/*.jar ../output
cp src/main/docker/* ../output
ls -l ../output

Since you are defining ROOT_FOLDER variable you can use it to navigate.

0
SHyx0rmZ On

You are still inside hello-concourse-repo and need to move output up one level.