BitBucket Pipelines Gradle build

Hi,

 

I'm wondering how to build a Java code repository with Gradle using Bitbucket pipelines.

I've currently got this code, but the build is always failing:

 

# This is a sample build configuration for Gradle.
# Check our guides at https://confluence.atlassian.com/x/VYk8Lw for more examples.
# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
image: java:8

pipelines:
  default:
    - step:
        script: # Modify the commands below to build your repository.
          - gradlew --version
          - gradlew build

 

I've also have the gradlew.bat and gradlew file in my repository and in the folder gradle under wrapper the gradle-wrapper.jar (and some scripts to be executed from the build.gradle).

Because I want to try Bitbucket pipelines on my Minecraft Mod out, gradle would also have to download some stuff to be able to compile the src code.

Currently it works all well on my local Windows machine, but on Bitbucket I'm getting the following error:

bash: gradlew: command not found


Thx in advance.

1 answer

1 accepted

2 votes
Accepted answer
Joshua Tjhin Atlassian Team Jan 11, 2017

Hey @MinecraftPlaye,

The gradlew is a script so you will need to execute it like a script.

Try:

pipelines:
  default:
    - step:
        script: # Modify the commands below to build your repository.
          - ./gradlew --version
          - ./gradlew build

Let me know how that goes

Sadly, it does not work:

bash: ./gradlew: Permission denied

Hm, wat I'm wondering, if it dienies me the permission to do that, will it denie me the permission to change a file with the gradlew setup (actually, after building it increases the version number automatically in the build.properties file wink )

Hi,

I just did some changes after some research: I added the bash keyword before every single of the two commands and now it's working. wink

Joshua Tjhin Atlassian Team Jan 12, 2017

Great to hear it's working! smile

Another workaround for the permission denied is to commit the gradlew file with executable permissions. 

http://stackoverflow.com/questions/17668265/gradlew-permission-denied

To make a file executable in Windows maybe try http://stackoverflow.com/questions/21691202/how-to-create-file-execute-mode-permissions-in-git-on-windows

Hello,

Here is my gradle script, to build and create EAR file for my project.

# You can specify a custom docker image from Docker Hub as your build environment.
image: qlik/gradle
 
pipelines:
  default:
    - step:
        script:
         
          - gradle clean
          - gradle test
          - gradle ear




Previously above script was working perfect (i was getting my ear ) from last two months , but today when i start build, it fails on clean command i.e

gradle clean 

+ gradle clean/tmp/bashScript853752692724365978.sh: line 22: gradle: command not found+ gradle clean/tmp/bashScript853752692724365978.sh: line 22: gradle: command not found

 

Can any body help me ? 

@Kashif-Ur-Rehman can you rerun that Pipeline? Is that issue still occurring?

@Philip Hodder, yes , i rerun this yesterday and today, and now it is working fine.
I dont know reason, that why same script was not running previous week ..

Do you have any idea ? 

My apologies @Kashif-Ur-Rehman. That was a bug that we accidentally introduced into the system last week. Specifically, we made a change to the way that we mount volumes inside the Docker container of your pipeline. We were able to detect, revert, and fix the issue before it was exposed to most of our users, but you seem to have unfortunately been affected by it.

Your script itself was not the problem and you should not encounter this issue anymore. smile

Oh I see, BTW, previous week I was changing my script with different docker images, I thought may be docker image got change, but it was not.

Any how, thanks for detailed explanation. 

Im am also experiencing this issue in some of our Pipeline branches:

/opt/atlassian/pipelines/agent/tmp/bashScript2757741404473080195.sh: line 16: grails: command not found

Is there a way how I can fix this by myself @Philip Hodder?  

 

 

It should be fixed for you too now. But if not (let me know if you're still seeing it), installing dependencies (such as grails) as part of you pipeline, or burning them inside your Docker image, should be a sufficient work around.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 06, 2018 in Bitbucket

Upgrade Best Practices

Hello! My name is Mark Askew and I am a Premier Support Engineer for products Bitbucket Server/Data Center, Fisheye & Crucible. Today, I want to bring the discussion that Jennifer, Matt, and ...

189 views 3 6
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you