Selenium 试图运行测试套件,但Jenkins没有下载最新代码

Selenium 试图运行测试套件,但Jenkins没有下载最新代码,selenium,docker,jenkins,bitbucket,codeception,Selenium,Docker,Jenkins,Bitbucket,Codeception,我正在使用Jenkins运行一个测试套件,我已经配置了一个作业来完成这项工作。我有一个执行所有步骤的管道脚本,但在LIVE上的最新版本中,通过在LIVE上添加一个新按钮,我的测试运行的代码版本没有该按钮,并且似乎没有提取最新的代码。我在剧本中做错了什么 我曾尝试从Bitbucket中提取最新代码,但没有成功,而是通过执行“docker compose build--build arg branch=${branch}apache”来构建分支 node { stage('Pull lates

我正在使用Jenkins运行一个测试套件,我已经配置了一个作业来完成这项工作。我有一个执行所有步骤的管道脚本,但在LIVE上的最新版本中,通过在LIVE上添加一个新按钮,我的测试运行的代码版本没有该按钮,并且似乎没有提取最新的代码。我在剧本中做错了什么

我曾尝试从Bitbucket中提取最新代码,但没有成功,而是通过执行“docker compose build--build arg branch=${branch}apache”来构建分支

node {
   stage('Pull latest Docker repo') { 
      git credentialsId: 'xyz',
          url: 'git@bitbucket.org:domain/myportal-docker.git'
   }
   stage('Install app') {
      sh 'docker-compose down'
      sh 'docker-compose build --no-cache mysql'
      if (params.buildapp == true){
        sh 'docker-compose build --build-arg BRANCH=${branch} apache'
      }
      sh 'docker-compose up -d'
   }
   stage('Set up Selenium') {
      try {
        sh 'docker rm selenium -f'
      }
      catch(exc) {
        echo 'No selenium container running'
      }
      sh 'docker pull selenium/standalone-chrome'
      sh 'docker run -d -p 4444:4444 --name=selenium --net=host -v /dev/shm:/dev/shm selenium/standalone-chrome:3.141.59-dubnium'
   }
   stage('Load tests') { 
      dir("../") {}
      git credentialsId: 'xyz',
          url: 'git@bitbucket.org:domain/my-tests.git'
   }
   stage('Run tests') {
      sh 'composer install'
      sh 'vendor/bin/codecept --debug run --steps tests/jenkins'
   }
}
测试运行良好,但不知何故,它们不是在最新代码上运行的,而是在主分支上运行的,但它没有最新的代码。
此外,我还有一份随需应变的工作,我想尝试一下,一旦我得到了一些信息,可能是你们中的一些人提供的。

可能与你的Dockerfile有关


您需要确保使用
ADD./yourcodefolder

@teddym6关闭文件。现在,我的Dockerfile如下所示:

来自webdevops/php apache:7.1

ARG WWW_根 ARG应用程序目录 ARG APP_ROOT=${WWW_ROOT}/${APP_DIR} ARG分支

ENV WEB_DOCUMENT_ROOT=${APP_ROOT}/htdocs

运行mkdir/root/.ssh/ 添加./.ssh//root/.ssh/ 运行chmod-R 0600/root/.ssh/* 运行echo“为代码使用分支${branch}” 运行git clone--branch${branch}--depth 1git@bitbucket.org:domain/myportal-docker.git${APP_ROOT}

WORKDIR${APP_ROOT}

运行mkdir-p运行时htdocs/assets 运行chmod-R a+w运行时htdocs/assets

WORKDIR/usr/src/app

复制app/local.php${app_ROOT}/config/local.php

加上/usr/src/app
WORKDIR/usr/src/app

这家伙还有其他想法吗

当我尝试以上所有方法时,没有任何效果。测试运行良好,但不是最新的代码


正如我在第一篇文章中所说,我知道,因为我们在第一页上有一个新按钮,而这个按钮不在我运行测试的版本上。

回到这里,因为它让我头疼,所以控制台输出如下所示:

  Started by timer
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] node
Running on Jenkins in /var/lib/jenkins/jobs/Autotest/workspace
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Pull latest Docker repo)
[Pipeline] git
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url git@bitbucket.org:domain/myportal-docker.git
 # timeout=10
Fetching upstream changes from git@bitbucket.org:domain/myportal-docker.git
 > git --version # timeout=10
using GIT_SSH to set credentials Jenkins Portal Tests Repo
 > git fetch --tags --progress git@bitbucket.org:domain/myportal-docker.git +refs/heads/*:refs/remotes/origin/*
 > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
 > git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision 20cdc207dc87e736983d6b28b5a81853c7c37f70 (refs/remotes/origin/master)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f 20cdc207dc87e736983d6b28b5a81853c7c37f70
 > git branch -a -v --no-abbrev # timeout=10
 > git branch -D master # timeout=10
 > git checkout -b master 20cdc207dc87e736983d6b28b5a81853c7c37f70
Commit message: "Got rid of the WORKDIR"
 > git rev-list --no-walk 20cdc207dc87e736983d6b28b5a81853c7c37f70 # timeout=10
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Install app)
[Pipeline] sh
[workspace] Running shell script
+ docker-compose down
Stopping workspace_apache_1 ... 
Stopping workspace_mysql_1  ... 
[2A[2K
Stopping workspace_apache_1 ... [32mdone[0m
[2B[1A[2K
Stopping workspace_mysql_1  ... [32mdone[0m
[1BRemoving workspace_apache_1 ... 
Removing workspace_mysql_1  ... 
[1A[2K
Removing workspace_mysql_1  ... [32mdone[0m
[1B[2A[2K
Removing workspace_apache_1 ... [32mdone[0m
[2BRemoving network workspace_frontend
Removing network workspace_backend
[Pipeline] sh
[workspace] Running shell script
+ docker-compose build --no-cache mysql
Building mysql
Step 1/2 : FROM mysql:5.7.24
 ---> ba7a93aae2a8
Step 2/2 : ADD mysql.cnf /etc/mysql/mysql.conf.d/mysql.cnf
 ---> cd3843490228
Successfully built cd3843490228
Successfully tagged workspace_mysql:latest
[Pipeline] echo
Will deploy from feature/docker-enablement
[Pipeline] echo
BuildApp Param false
[Pipeline] sh
[workspace] Running shell script
+ docker-compose up -d
Creating network "workspace_frontend" with the default driver
Creating network "workspace_backend" with the default driver
Creating workspace_mysql_1 ... 
Creating workspace_mysql_1
[1A[2K
Creating workspace_mysql_1 ... [32mdone[0m
[1BCreating workspace_apache_1 ... 
Creating workspace_apache_1
[1A[2K
Creating workspace_apache_1 ... [32mdone[0m
[1B[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Set up Selenium)
[Pipeline] sh
[workspace] Running shell script
+ docker rm selenium -f
selenium
[Pipeline] sh
[workspace] Running shell script
+ docker pull selenium/standalone-chrome
Using default tag: latest
latest: Pulling from selenium/standalone-chrome
Digest: sha256:c478febf26729b7cc27e2fac7d10fa79cf2519b5ab83f9cf82705248258b6495
Status: Image is up to date for selenium/standalone-chrome:latest
[Pipeline] sh
[workspace] Running shell script
+ docker run -d -p 4444:4444 --name=selenium --net=host -v /dev/shm:/dev/shm selenium/standalone-chrome:3.141.59-dubnium
WARNING: Published ports are discarded when using host network mode
952481c15140f1b9fe797cbee495268d7fd191c4ec07194297e19b27109f829a
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Load tests)
[Pipeline] dir
Running in /var/lib/jenkins/jobs/Autotest
[Pipeline] {
[Pipeline] }
[Pipeline] // dir
[Pipeline] git
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url git@bitbucket.org:domain/myportal-docker.git
 # timeout=10
Fetching upstream changes from git@bitbucket.org:domain/myportal-docker.git
 > git --version # timeout=10
using GIT_SSH to set credentials Jenkins Portal Tests Repo
 > git fetch --tags --progress git@bitbucket.org:domain/myportal-docker.git +refs/heads/*:refs/remotes/origin/*
 > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
 > git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision a5ddc6742c13e3b8c37e7ebda625fd8d89b1386a (refs/remotes/origin/master)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f a5ddc6742c13e3b8c37e7ebda625fd8d89b1386a
 > git branch -a -v --no-abbrev # timeout=10
 > git branch -D master # timeout=10
 > git checkout -b master a5ddc6742c13e3b8c37e7ebda625fd8d89b1386a
Commit message: "Commented out the forum request button test"
 > git rev-list --no-walk a5ddc6742c13e3b8c37e7ebda625fd8d89b1386a # timeout=10
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Run tests)
[Pipeline] sh
[workspace] Running shell script
+ composer install
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Nothing to install or update
Generating autoload files
[Pipeline] sh
[workspace] Running shell script
+ vendor/bin/codecept --debug run --steps tests/jenkins
Codeception PHP Testing Framework v2.5.2
Powered by PHPUnit 6.5.13 by Sebastian Bergmann and contributors.
Running with seed:

在完成上述所有操作之后,测试正常运行,但正如该线程所说,不是在最新的代码上运行。

params.buildapp为false,因此它没有构建apache容器。只有在构建此容器时,才会从您的repo中提取代码。

在我看来,您缺少用
--无缓存
参数重新构建包含源代码的容器。您没有包含
docker compose
文件,但您可能必须运行
docker compose build--no cache--build arg BRANCH=${BRANCH}apache
,以便使用最新的git提交来重建映像。我刚才已经完成了,但它仍然不是最新的代码,您是指myportal docker中的docker compose文件吗?谢谢你的回答你的意思是在复制docker文件中的部分后,我需要添加这一行add./yourcodefolder?当你说code folder时,我到底需要什么?我的测试?这是你的workdir在你的例子中我可以看到它是`/usr/src/app`我现在知道了,所以我现在要做的就是在复制app/local.php${app_ROOT}/config/local.php之后添加./usr/src/app,以正确的方式关闭文件?非常感谢。我已经改变了它,它没有做任何不同的事情,仍然没有最新的代码。现在,您可以看到我的Dockerfile在进行更改后的样子。
ADD/usr/src/app
添加/usr/src/app WORKDIR/usr/src/app
如果(params.buildapp==true)我就去掉了这一行,现在当我尝试构建应用程序容器时,我得到了这样的结果:Curl错误:使用params:{“desiredCapabilities”:{“browserName”:“chrome”}无法连接到本地主机端口4444:连接被拒绝[39m]未设置WebDriver时调用了[36m WebDriver::debugWebDriverLogs方法[39m[36m WebDriver::\未设置WebDriver时调用了saveScreenshot方法[39m[36m WebDriver:::\未设置WebDriver时调用了savePageSource方法[39m]