从Jenkinsfile调用gradlew

时间:2016-12-06 21:42:33

标签: jenkins gradle continuous-integration gradlew

我的项目在根目录中包含一个gradlew shell脚本和一个Jenkins文件。 Jenkins文件包含:

import jenkins.model.Jenkins
node('jnlp-slave-with-java-build-tools') {
    sh 'gradlew build -x check'
}

当我将其推送到我的存储库时,Jenkins找到了Jenkinsfile并尝试运行gradlew。然而,它失败了,通知我:

Running on ECS-2d51eb80546b7 in /home/jenkins/workspace/tems_chore_add-jenkins-file-7VBJJMGP4JS3QPUSNL2ROWDE3ECV5A4EJQJ6Z5VCSPDK7UABIPVQ
[Pipeline] {
[Pipeline] sh
[tems_chore_add-jenkins-file-7VBJJMGP4JS3QPUSNL2ROWDE3ECV5A4EJQJ6Z5VCSPDK7UABIPVQ] Running shell script
+ gradlew build -x check
/home/jenkins/workspace/tems_chore_add-jenkins-file-7VBJJMGP4JS3QPUSNL2ROWDE3ECV5A4EJQJ6Z5VCSPDK7UABIPVQ@tmp/durable-838b5837/script.sh: 2: /home/jenkins/workspace/tems_chore_add-jenkins-file-7VBJJMGP4JS3QPUSNL2ROWDE3ECV5A4EJQJ6Z5VCSPDK7UABIPVQ@tmp/durable-838b5837/script.sh: gradlew: not found
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline

GitHub has been notified of this commit’s build result

ERROR: script returned exit code 127
Finished: FAILURE

如何修改我的Jenkins文件以便找到gradlew脚本并正确运行?

跟进#1

以下内容:

import jenkins.model.Jenkins
node('jnlp-slave-with-java-build-tools') {
    sh './gradlew build -x check'
}

结果:

tems_chore_add-jenkins-file-7VBJJMGP4JS3QPUSNL2ROWDE3ECV5A4EJQJ6Z5VCSPDK7UABIPVQ] Running shell script
+ ./gradlew build -x check
/home/jenkins/workspace/tems_chore_add-jenkins-file-7VBJJMGP4JS3QPUSNL2ROWDE3ECV5A4EJQJ6Z5VCSPDK7UABIPVQ@tmp/durable-3c901cf0/script.sh: 2: /home/jenkins/workspace/tems_chore_add-jenkins-file-7VBJJMGP4JS3QPUSNL2ROWDE3ECV5A4EJQJ6Z5VCSPDK7UABIPVQ@tmp/durable-3c901cf0/script.sh: ./gradlew: not found

所以仍然会收到“未找到”错误。

跟进#2

运行:

import jenkins.model.Jenkins
node('jnlp-slave-with-java-build-tools') {
    files = sh (script: 'ls -l',
                returnStdout: true).trim()
    echo "${files}"

    sh './gradlew build -x check'
}

输出total 0,表明我可能在错误的目录中或有权限问题?欢迎提出建议!

1 个答案:

答案 0 :(得分:5)

这对我来说是一个误解:我推测Jenkins会在运行我的Jenkins文件之前删除回购,但事实并非如此,我需要自己添加:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="pricing-customer col-sm-12 col-sm-3 text-center">
  <h3><?php echo $t_title; ?></h3>
  <p class="pricing-number">$ 70</p>
  <br>
  <p class="pricing-monthes">per week/month</p>
  <p class="pricing-emails">100 000 emails</p>
</div>

<div class="pricing-customer col-sm-12 col-sm-3 text-center">
  <h3><?php echo $t_title; ?></h3>
  <p class="pricing-number">$ 70</p>
  <br>
  <p class="pricing-monthes">per week/month</p>
  <p class="pricing-emails">100 000 emails</p>
</div>

<div class="pricing-customer col-sm-12 col-sm-3 text-center default">
  <h3><?php echo $t_title; ?></h3>
  <p class="pricing-number">$ 70</p>
  <br>
  <p class="pricing-monthes">per week/month</p>
  <p class="pricing-emails">100 000 emails</p>
</div>

我现在收到了无关的错误。

documentation中介绍了这一点,但我的错误印象是我的设置中没有必要。