小编Ita*_*not的帖子

如何打印groovy变量?

我在Jenkins管道中有以下代码:

stage ('Question') {
    try {
        timeout(time: 1, unit: 'MINUTES') {
            userInput = input message: 'Choose server to publish to:', ok: '', parameters: [
                [$class: 'hudson.model.ChoiceParameterDefinition', choices: 'pc-ensureint\nother-server', description: 'Choose server to publish to:', name: 'server']
        ] 
      }
    } catch (err) {
        userInput = [server: 'pc-ensureint'] // if an error is caught set this value
    }
}

node () {
    println ${server}
}
Run Code Online (Sandbox Code Playgroud)

我正在尝试解决"ChoiceParameterDefinition"中设置的"server"变量的问题.

当我运行构建时,我收到以下错误:

java.lang.NoSuchMethodError: No such DSL method '$' found among steps [AddInteractivePromotion, ArtifactoryGradleBuild, ArtifactoryMavenBuild, ConanAddRemote, ConanAddUser, InitConanClient, …
Run Code Online (Sandbox Code Playgroud)

variables groovy jenkins jenkins-pipeline

17
推荐指数
2
解决办法
9万
查看次数

Jenkins:GitSCM以一个独立的头状态完成克隆,我怎样才能确保检出正确的分支名称?

我写了一个Jenkins管道,它克隆了一个git存储库并运行了一个MSBUILD构建.

我使用GitSCM将存储库克隆到工作区中,如下所示:

stage ('Checkout SCM & Merge master to feature branch') {
    checkout([$class: 'GitSCM', branches: [[name: '*/feature/*']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '99f978af-XXXX-XXXX-8147-2cf8f69ef864', url: 'http://TFS_SERVER:8080/tfs/DefaultCollection/PC_International/_git/REPO_NAME']]])
}
Run Code Online (Sandbox Code Playgroud)

在克隆步骤发生后,HEAD指向一个独立的头部,我不明白为什么.

Started by user itai ganot
[Pipeline] node
Running on master in C:\Program Files (x86)\Jenkins\workspace\bbb
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Setup)
[Pipeline] deleteDir
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Checkout SCM & Merge master to feature branch)
[Pipeline] checkout
Cloning the remote Git repository
Cloning repository http://pctfs1:8080/tfs/DefaultCollection/PC_International/_git/Ensure-pcs-intl …
Run Code Online (Sandbox Code Playgroud)

git jenkins

13
推荐指数
2
解决办法
3058
查看次数

如何使用命令行在Android Studio外部安装Android约束布局工具?

我正在手动安装Android-Gradle构建服务器,这意味着我没有使用Android Studio SDK,而是使用android update sdk命令安装所需的工具.

我能够安装构建成功完成所需的大多数软件包,但有些工具我无法找到:

com.android.support.constraint:constraint-layout:1.0.0-alpha(1-4)
com.android.support.constraint:constraint-layout-solver:1.0.0-alpha(1-4)
Run Code Online (Sandbox Code Playgroud)

在@CommonsWare评论之后,这是构建的输出(这表明工具正在存储库中自动查找但未找到:

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':Company'.
> Could not resolve all dependencies for configuration ':Company:_productionDebugCompile'.
   > Could not find com.android.support.constraint:constraint-layout:1.0.0-alpha4.
     Searched in the following locations:
         https://jcenter.bintray.com/com/android/support/constraint/constraint-layout/1.0.0-alpha4/constraint-layout-1.0.0-alpha4.pom
         https://jcenter.bintray.com/com/android/support/constraint/constraint-layout/1.0.0-alpha4/constraint-layout-1.0.0-alpha4.jar
         http://dl.bintray.com/optimizely/optimizely/com/android/support/constraint/constraint-layout/1.0.0-alpha4/constraint-layout-1.0.0-alpha4.pom
         http://dl.bintray.com/optimizely/optimizely/com/android/support/constraint/constraint-layout/1.0.0-alpha4/constraint-layout-1.0.0-alpha4.jar
         file:/Users/itai/work_repos/Company-Android_fork/.gradle/android-sdk-linux/extras/android/m2repository/com/android/support/constraint/constraint-layout/1.0.0-alpha4/constraint-layout-1.0.0-alpha4.pom
         file:/Users/itai/work_repos/Company-Android_fork/.gradle/android-sdk-linux/extras/android/m2repository/com/android/support/constraint/constraint-layout/1.0.0-alpha4/constraint-layout-1.0.0-alpha4.jar
         file:/Users/itai/work_repos/Company-Android_fork/.gradle/android-sdk-linux/extras/google/m2repository/com/android/support/constraint/constraint-layout/1.0.0-alpha4/constraint-layout-1.0.0-alpha4.pom
         file:/Users/itai/work_repos/Company-Android_fork/.gradle/android-sdk-linux/extras/google/m2repository/com/android/support/constraint/constraint-layout/1.0.0-alpha4/constraint-layout-1.0.0-alpha4.jar
     Required by:
         Company-Android_fork:Company:unspecified

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD …
Run Code Online (Sandbox Code Playgroud)

android

11
推荐指数
2
解决办法
6320
查看次数

10
推荐指数
2
解决办法
4197
查看次数

如何正确编写关于Jenkins管道Jenkinsfile中的BooleanParameter的if语句?

我正在设置Jenkins管道Jenkinsfile,我想检查是否设置了booleanparameter.

这是文件的相关部分:

node ("master") {
        stage 'Setup' (
                [[$class: 'BooleanParameterValue', name: 'BUILD_SNAPSHOT', value: 'Boolean.valueOf(BUILD_SNAPSHOT)']],
Run Code Online (Sandbox Code Playgroud)

据我所知,这是访问booleanparameter的方法,但我不知道如何陈述IF语句本身.

我在想做类似的事情:

if(BooleanParameterValue['BUILD_SNAPSHOT']){...
Run Code Online (Sandbox Code Playgroud)

请写这句话的正确方法是什么?

jenkins jenkins-pipeline

8
推荐指数
3
解决办法
2万
查看次数

8
推荐指数
1
解决办法
2215
查看次数

如何通过URL访问lastSuccessfulBuild中Jenkins创建的工件?

我正在使用Jenkins管道构建一个Android应用程序.

当构建成功完成时,它会创建一个.apk文件.

我希望QA团队的成员能够在上传Google商店之前下载此文件并测试应用程序,因此我希望这些用户(可以访问Jenkins服务器)能够通过URL上的URL访问该工件. Jenkins服务器如此SO问题所示,但由于某种原因,我用来尝试下载工件的URL一直给我404错误.

这些是我试图访问的链接但无济于事:

https://company-ci-server.company.net/job/Itai_repos/job/Product-Android/job/develop/lastSuccessfulBuild/build/outputs/apk/Company-production-release.apk

https://company-ci-server.company.net/job/Itai_repos/job/Product-Android/job/develop/lastSuccessfulBuild/artifact/product-production-release.apk
Run Code Online (Sandbox Code Playgroud)

该作业被配置为多分支,这意味着Jenkins正在GitHub中观看项目,索引所有分支以及每当提交工作开始时......这就是为什么链接太久你想知道...

那么我做错了什么?为什么我不能通过URL访问工件?

artifacts jenkins jenkins-pipeline

8
推荐指数
1
解决办法
9009
查看次数

如何显示在Jenkins中运行构建所花费的时间?

我正在使用Jenkins管道配置Android应用程序构建过程.

在构建的开始和结束时,将消息发送到相关的Slack通道.

Jenkinsfile的相关部分如下所示:

slackSend (channel: '#slack-test', color: 'warning', message: "Finished: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' State: ${STATE}.   Artifacts can be viewed here: ${env.BUILD_URL}artifact/Product/build/outputs/ ")
Run Code Online (Sandbox Code Playgroud)

除了上述信息之外,我还想包括构建运行到该消息所花费的时间,该消息通知构建的结束.

是否可以不添加任何外部插件?如果有一个环境变量保存这些信息,那将是完美的,但我找不到这样的变量.

build jenkins jenkins-pipeline

7
推荐指数
3
解决办法
9828
查看次数

如何将git凭据添加到构建中,以便能够在shell代码中使用?

我写了以下Jenkinsfile:

node("master") {
 def artifactory_creds = 'XXXXXXX'
 def git_creds = 'XXXXXXX'
  java = docker.image('openjdk:8-jdk')
  java.pull()
  java.inside("-u root --ulimit core=99999999") {
      withCredentials([ // Use Jenkins credentials ID of artifactory
        [$class: 'UsernamePasswordMultiBinding', credentialsId: artifactory_creds, usernameVariable: 'A_USER', passwordVariable: 'A_PASS'],
        [$class: 'UsernamePasswordMultiBinding', credentialsId: git_creds, usernameVariable: 'G_USER', passwordVariable: 'G_PASS'] // Use Jenkins credentials ID of git
        ]) {
        sh '''
        cd $PWD && git clone ${G_USER}:${G_PASS}@github.com/ganoti/Product-Android .
            NDK_VER="r12b"
            SDK_VER="r24.4.1"
            export GRADLE_USER_HOME=$PWD/Product-Android/.gradle
            export PATH=$PATH:$GRADLE_USER_HOME:$GRADLE_USER_HOME/android-ndk-$NDK_VER
        #    apt-get update && apt-get install gcc-multilib lib32z1 make file -y
            if …
Run Code Online (Sandbox Code Playgroud)

groovy jenkins jenkins-pipeline

6
推荐指数
1
解决办法
2万
查看次数

Groovy:如何将操纵的字符串定义为变量?

我正在编写一个Jenkins管道作为Android应用程序的代码.

我有以下字符串:

BUILDFLAV = "Staging"
BUILDTYPE = "Debug"
Run Code Online (Sandbox Code Playgroud)

我想定义另一个名为artifact_name的变量,它看起来像:

product_name-BUILDFLAV(in lowercase)-BUILDTYPE(in lowercase).apk
Run Code Online (Sandbox Code Playgroud)

例如:

App01-staging-debug.apk
Run Code Online (Sandbox Code Playgroud)

因为我是groovy的新手,所以我不确定我是否正确地做到了.

我已经定义了2个变量:

aa = BUILDFLAV[0].toLowerCase()+BUILDFLAV.substring(1)
bb = BUILDTYPE[0].toLowerCase()+BUILDTYPE.substring(1)
Run Code Online (Sandbox Code Playgroud)

这允许我将每个字符串的第一个字符从大写更改为小写.

然后,我希望artifact_name变量看起来像这样:

App01-$(aa}-${bb}.apk
Run Code Online (Sandbox Code Playgroud)

所以我尝试过这样的事情:

artifact_name = "App01-${BUILDFLAV[0]}.toLowerCase()+${BUILDFLAV}.substring(1)+${BUILDTYPE[0]}.toLowerCase()+${BUILDTYPE}.substring(1).apk"
Run Code Online (Sandbox Code Playgroud)

但它给我一个错误.

但是,这样做有效,但似乎有更优雅的方法:

BUILDFLAV = "Staging"
BUILDTYPE = "Debug"
aa = BUILDFLAV[0].toLowerCase()+BUILDFLAV.substring(1)
bb = BUILDTYPE[0].toLowerCase()+BUILDTYPE.substring(1)
ARTIFACT_NAME = "App01-${aa}-${bb}.apk"
Run Code Online (Sandbox Code Playgroud)

如果你问自己为什么我不是从一开始就用小写设置变量是因为在构建中运行的gradle任务是使用第一个字母大写约定而我想要实现的是与更高级的步骤有关构建.

是否有可能通过在vars"aa"和"bb"中仅用一行来完成相同的结果?像上面带有artifact_name的例子...

groovy jenkins jenkins-pipeline

6
推荐指数
1
解决办法
2万
查看次数

标签 统计

jenkins ×8

jenkins-pipeline ×8

groovy ×5

android ×1

artifacts ×1

build ×1

dsl ×1

git ×1

variables ×1