Bitbucket Pipelines使用Docker容器来执行任务,默认情况下Docker容器以root身份运行.这是NPM生命周期脚本的问题,因为NPM在运行脚本时尝试降级其权限.
当执行postinstall脚本,NPM抛出一个错误,它cannot run in wd %s %s (wd=%s).最简单的解决方案是使用--unsafe-perm标志运行npm install ,但我不喜欢这种方法.
Docker 编写Dockerfiles 的最佳实践表明:
如果服务可以在没有权限的情况下运行,请使用USER更改为非root用户.
配置典型的Docker容器时,我会创建一个新的非root用户并以此用户身份运行我的npm脚本.
阅读Pipelines文档后,我找不到任何与Docker的USER命令等效的内容.我也许能使用useradd,chown并且su(没有测试尚未),但有一个简单的解决方案?
不幸的是增加useradd,chown而su到bitbucket-pipelines.yml脚本部分管道破裂,并导致失败的repo:push网络挂接.
image: node:6.2
pipelines:
default:
- step:
script:
- useradd --user-group --create-home --shell /bin/false node
- chown -R node: /opt/atlassian/bitbucketci/agent/build
- su -s /bin/sh -c "npm install" node
- su -s /bin/sh -c …Run Code Online (Sandbox Code Playgroud) continuous-integration bitbucket node.js docker bitbucket-pipelines
我想在两个步骤中共享一个变量。
我将其定义为:
- export MY_VAR="FOO-$BITBUCKET_BUILD_NUMBER"
Run Code Online (Sandbox Code Playgroud)
但是当我尝试在其他步骤中打印它时:
- echo $MY_VAR
Run Code Online (Sandbox Code Playgroud)
它是空的。
我如何共享这样的变量?
使用新的Bitbucket管道功能,如何从它旋转的docker容器SSH到我的分段盒?
我的管道中的最后一步是.sh在登台时部署必要代码的文件,但由于我的登台框使用公钥认证而不知道docker容器,因此SSH连接被拒绝.
无论如何不通过SSH使用密码身份验证来解决这个问题(通过不断选择通过公钥进行身份验证,这也导致了我的问题.)?
我试图运行以下步骤,但它不执行“如果”步骤(第5和第6行)(我很确定它们应该是不存在的,因为要测试的目录不存在,我尝试了多种bash格式,但它们都失败了,是否有一种方法可以测试比我正在使用的条件更好的条件?
- step:
name: Google Cloud SDK Installation
caches:
- pip
- cloudsdk
script:
- export ENV=dev
- source scripts/setenv.sh
- export CLOUDSDK_CORE_DISABLE_PROMPTS=1
- SDK_FILENAME=google-cloud-sdk-$SDK_VERSION-linux-x86_64.tar.gz
- if [ ! -e ${HOME}/google-cloud-sdk ] ; then `curl -O -J https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/${SDK_FILENAME}`; fi
- if [ ! -e ${HOME}/google-cloud-sdk ] ; then `tar -zxvf ${SDK_FILENAME} --directory ${HOME}`; fi
- export PATH=${PATH}:${HOME}/google-cloud-sdk/bin
- GAE_PYTHONPATH=${HOME}/google_appengine
- export PYTHONPATH=${PYTHONPATH}:${GAE_PYTHONPATH}
- python scripts/fetch_gae_sdk.py $(dirname "${GAE_PYTHONPATH}")
Run Code Online (Sandbox Code Playgroud) 我的Bibucket管道中有一个node_modules缓存,并添加了新模块(例如yarn add react-modal)-如何使Bitbucket管道检测到新的yarn.lock并使它的缓存无效?
我已使用以下配置 ( bitbucket-pipelines.yml )为我的 Web 应用程序设置了持续部署。
pipelines:
branches:
master:
- step:
name: Deploy to production
trigger: manual
deployment: production
caches:
- node
script:
# Install dependencies
- yarn install
- yarn global add gulp-cli
# Run tests
- yarn test:unit
- yarn test:integration
# Build app
- yarn run build
# Deploy to production
- yarn run deploy
Run Code Online (Sandbox Code Playgroud)
虽然这有效,但我想通过并行运行单元和集成测试步骤来提高构建速度。
pipelines:
branches:
master:
- step:
name: Install dependencies
script:
- yarn install
- yarn global add gulp-cli
- parallel:
- …Run Code Online (Sandbox Code Playgroud) 我正在尝试配置一个 Bitbucket 管道来执行 SonarQube 管道,但 Bitbucket 抱怨管道步骤为空、为空或丢失。
我已将 SONAR_TOKEN 定义为具有正确令牌的项目变量。
这是我当前的 bitbucket-pipeline.yml 文件:
image: atlassian/default-image:2
clone:
depth: full
definitions:
caches:
sonar: ~/.sonar/cache
steps:
- step: &sonarcloud
name: Analyze on SonarCloud
caches:
- sonar
script:
- pipe: sonarsource/sonarcloud-scan:0.1.5
variables:
SONAR_TOKEN: ${SONAR_TOKEN}
pipelines:
branches:
'*':
- step: *sonarcloud
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我有一个 bitbucket 管道 yml,我有运行测试脚本的步骤和运行无服务器部署脚本的步骤。我是否需要在每一步进行 npm install 或者第一个 npm install 是否会继续执行并足以满足后续的每个步骤。除此之外,引擎盖下发生了什么?我知道 Docker 容器已创建;每一步都只是更新容器吗?
- step:
name: Test and Build
script:
- npm install --no-package-lock
- npm run test
- step:
name: Deploy Serverless
script:
- npm i serverless -g
- npm install --no-package-lock
- npm run deploy
Run Code Online (Sandbox Code Playgroud) 如何使用 bitbucket-pipelines.yml 文件在管道中标记 git 提交?
使用的工具:
Java 8
Gradle 4.0
Selenium
Selenium Grid
TestNG
Docker
Bitbucket
Bitbucket pipelines
Run Code Online (Sandbox Code Playgroud)
当我通过 bitbucket 管道执行测试时,出现以下错误:
当我在本地运行测试时,一切正常。关于如何解决这个问题有什么想法吗?