gpt4 book ai didi

jenkins - 在 jenkins 管道脚本中获取 gradle 变量

转载 作者:行者123 更新时间:2023-12-04 17:44:45 25 4
gpt4 key购买 nike

我正在尝试使用 groovy 构建脚本将我的构建管道迁移到“管道插件”。

我的管道通常是:

  • 测试(毕业)
  • 集成测试 (gradle)
  • 构建 (gradle)
  • 发布(神器)

  • 我想在我的 jenkins 构建脚本中使用版本/组等 gradle 变量来发布到工件中的正确文件夹。过去,artifactory 插件会为我处理一些事情。如何做到这一点?

    对于单个 gradle 项目,我使用如下内容:
    node('master')
    {
    def version = 1.0
    def gitUrl = 'some.git'
    def projectRoot = ""
    def group = "dashboard/frontend/"
    def artifactName = "dashboard_ui"
    def artifactRepo = "ext-release-local"

    stage "git"

    git branch: 'develop', poll: true, url: "${gitUrl}"

    dir(projectRoot)
    {

    sh 'chmod +x gradlew'
    stage "test"
    sh './gradlew clean test'

    stage "build"
    sh './gradlew build createPom'

    stage "artifact"
    def server = Artifactory.server('artifactory_dev01')
    def uploadSpec = """{
    "files": [
    {
    "pattern": "build/**.jar",
    "target": "${artifactRepo}/$group/${artifactName}/${version}/${artifactName}-${version}.jar"
    },
    {
    "pattern": "pom.xml",
    "target": "${artifactRepo}/$group/${artifactName}/${version}/${artifactName}.pom"
    }
    ]
    }"""
    def buildInfo1 = server.upload spec: uploadSpec
    server.publishBuildInfo buildInfo1
    }
    }

    最佳答案

    以供将来引用这里使用更现代的声明性管道的示例:

    pipeline {
    agent any
    stages {
    stage('somestage') {
    steps {
    script {
    def version = sh (
    script: "./gradlew properties -q | grep \"version:\" | awk '{print \$2}'",
    returnStdout: true
    ).trim()
    sh "echo Building project in version: $version"

    }
    }
    }
    }
    }

    也可以看看:
  • Gradle plugin project version number
  • How to do I get the output of a shell command executed using into a variable from Jenkinsfile (groovy)?
  • 关于jenkins - 在 jenkins 管道脚本中获取 gradle 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39140744/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com