Jenkins管道:使用配置文件提供程序在Docker容器中运行的Maven

时间:2020-08-28 06:23:49

标签: jenkins jenkins-pipeline

我已经设置了以下声明式Jenkins管道。它将在代理上启动Maven Docker容器,然后执行Maven任务。

此外,我还通过Config File Provider插件设置了settings.xml,该插件将用于Maven命令。

运行构建时,它将启动Docker容器,但出现以下错误消息:

java.lang.NoSuchMethodError: No such DSL method 'withMaven' found among steps [ansiColor, archive, awaitDeployment, bat, build, catchError, checkout, deleteDir, dir, dockerFingerprintFrom, dockerFingerprintRun, echo, emailext, emailextrecipients, envVarsForTool, error, fileExists, findBuildScans, getContext, git, input, isUnix, jiraComment, jiraIssueSelector, jiraSearch, junit, library, libraryResource, load, lock, mail, milestone, node, parallel, powershell, properties, publishHTML, pwd, readFile, readTrusted, resolveScm, retry, rocketSend, script, sh, sleep, sshagent, stage, stash, step, timeout, timestamps, tm, tool, unarchive, unstash, validateDeclarativePipeline, waitForQualityGate, waitUntil, withContext, withCredentials, withDockerContainer, withDockerRegistry, withDockerServer, withEnv, wrap, writeFile, ws] or symbols [absolute, all, allOf, always, ant, antFromApache, antOutcome, antTarget, any, anyOf, apiToken, architecture, archiveArtifacts, artifactManager, authorizationMatrix, batchFile, bitbucket, booleanParam, branch, brokenBuildSuspects, brokenTestsSuspects, buildButton, buildDiscarder, buildingTag, bzt, caseInsensitive, caseSensitive, certificate, changeRequest, changelog, changeset, checkoutToSubdirectory, checkstyle, choice, choiceParam, cleanWs, clock, cloud, command, configFile, configFileProvider, credentials, cron, crumb, culprits, default, defaultView, demand, developers, disableConcurrentBuilds, disableResume, docker, dockerCert, dockerfile, downloadSettings, downstream, dumb, durabilityHint, envVars, environment, equals, executor, expression, file, fileParam, filePath, fingerprint, flyway, flywayrunner, frameOptions, freeStyle, freeStyleJob, fromScm, fromSource, git, gitHubBranchDiscovery, gitHubBranchHeadAuthority, gitHubExcludeArchivedRepositories, gitHubForkDiscovery, gitHubPullRequestDiscovery, gitHubSshCheckout, gitHubTagDiscovery, gitHubTrustContributors, gitHubTrustEveryone, gitHubTrustNobody, gitHubTrustPermissions, gitLabBranchDiscovery, gitLabBranchHeadAuthority, gitLabForkDiscovery, gitLabTagDiscovery, gitLabTrustEveryone, gitLabTrustMembers, gitLabTrustNobody, gitLabTrustPermissions, gitParameter, github, githubPush, gitlabAvatar, gitlabPersonalAccessToken, globalConfigFiles, gradle, headRegexFilter, headWildcardFilter, hyperlink, hyperlinkToModels, inheriting, inheritingGlobal, installSource, isRestartedRun, jacoco, jdk, jdkInstaller, jgit, jgitapache, jnlp, jobName, label, lastDuration, lastFailure, lastGrantedAuthorities, lastStable, lastSuccess, legacy, legacySCM, list, local, location, logComment, logRotator, loggedInUsersCanDoAnything, masterBuild, maven, maven3Mojos, mavenErrors, mavenMojos, mavenWarnings, modernSCM, mrTriggerComment, myView, newContainerPerStage, node, nodeProperties, nodejs, nodejsci, nonInheriting, none, not, overrideIndexTriggers, paneStatus, parameters, password, pattern, perfReport, performanceReport, performanceTest, permanent, pipeline-model, pipelineTriggers, plainText, plugin, pmd, pollSCM, preserveStashes, previous, projectNamingStrategy, proxy, queueItemAuthenticator, quietPeriod, rateLimitBuilds, recipients, relative, requestor, run, runParam, schedule, scmRetryCount, scriptApprovalLink, search, security, shell, skipDefaultCheckout, skipNotifications, skipStagesAfterUnstable, slave, sourceRegexFilter, sourceWildcardFilter, sshPublisher, sshPublisherDesc, sshTransfer, sshUserPrivateKey, stackTrace, standard, status, string, stringParam, swapSpace, tag, teamSlugFilter, testCase, text, textParam, tmpSpace, toolLocation, unsecured, upstream, upstreamDevelopers, userSeed, usernameColonPassword, usernamePassword, viewsTabBar, weather, withAnt, withSonarQubeEnv, workspace, zfs, zip] or globals [currentBuild, docker, env, params, pipeline, scm, template]

已安装Maven插件。 documentation here最初看起来很有希望,但相关部分尚待完成。

对詹金斯使用“ withMaven”和“ docker.image(...)。inside {...}” 声明性管道
TODO使用Jenkins声明式管道提供了一个示例

Jenkinsfile

pipeline {
    agent any
  
    environment {
        // Maven settings
        MAVEN_DOCKER_IMAGE = 'maven:3.6-jdk-8'
        MAVEN_DOCKER_ARGS = "-v ${HOME}/.m2:/.m2"    
    }

    stages {
        stage('Compile') {
            steps {
                script {
                    docker.image(MAVEN_DOCKER_IMAGE).inside("${MAVEN_DOCKER_ARGS}") {
                        withMaven(mavenSettingsConfig: 'maven-settings') {
                            sh "mvn clean compile"
                        }
                    }
                }
            }
        }
    }
}

0 个答案:

没有答案
相关问题