I have a concourse pipeline:
groups: []
resources:
- name: source-code
  type: git
resource_types: []
jobs:
- name: build
  public: true
  plan:
  - get: source-code
  - task: build
    privileged: true
    config:
      platform: linux
      image_resource:
        type: docker-image
        source:
          repository: java
          tag: openjdk-8-alpine
      run:
        path: sh
        args:
        - -exc
        - |
          set -e -u -x
          MVN_VERSION=$(cat pom.xml | grep "^    <version>.*</version>$" | awk -F'[><]' '{print $3}')
          **CUSTOM_VERSION = [POM_FILE_VERSION]-build.[NO_OF_COMMITS_IN_BRANCH]** 
      inputs:
      - name: source-code
Using Unix commands, I want to create the custom version:
CUSTOM_VERSION = [POM_FILE_VERSION]-build.[NO_OF_COMMITS_IN_BRANCH]
For [POM_FILE_VERSION], I have found the code:
MVN_VERSION=$(cat pom.xml | grep "^    <version>.*</version>$" | awk -F'[><]' '{print $3}')
But for [NO_OF_COMMITS_IN_BRANCH], i don't know how get that data from git resource. Can anyone help please ?
                        
The Concourse git resource doesn't provide the number of commits in the branch.
I suggest to use something more meaningful like the commit hash, which the Concourse git resource makes available as the
.git/short_reffile.If you really need to use the number of commits (but why?), then you need to run the
gitcommand directly in the Concourse task, for examplegit rev-list --count HEAD.In the pipeline above, the task is using the
openjdk-8-alpineDocker image from thejavarepository. If that image containsgit, then you are all set. If not, I suggest first to see if thejavarepository offers a variation ofopenjdk-8-alpinewith git installed. If not, you have to create your own Docker image, based offopenjdk-8-alpine.Security note: you have
privileged: truespecified. Probably you don't need it.