下一阶段丢失了IBM DevOps交付管道上的当前节点版本

时间:2018-11-26 17:35:48

标签: node.js ibm-cloud upgrade pipeline

在Bluemix管道的第一阶段,通过遵循SO 42269590article的大致指示,我能够安装NVM并使用以下命令更新到最新版本的nodejs:

#!/bin/bash

echo " "
echo "= = = = = = = = = = = "
echo "PATH $PATH" | tr ':' '\n'

echo " "
echo "= = = = = = = = = = = "
echo "loading nvm ..."
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash

# make nvm available immediately
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

echo " "
echo "= = = = = = = = = = = "
echo "Is nvm installed?"
command -v nvm
nvm --version

# based on this recommendation in the error logs
# nvm is not compatible with the npm config "prefix" option: currently set to "/home/pipeline/.npm-global"
# Run `npm config delete prefix` or `nvm use --delete-prefix v11.2.0` to unset it.
echo " "
echo "= = = = = = = = = = = "
echo "config delete prefix..."
npm config delete prefix


echo " "
echo "= = = = = = = = = = = "
echo "Installing the latest version of nodejs"
nvm install node

# remember to add below directory name to 
# Build Archive Directory field of this configuration
mkdir build_archive_dir

echo " "
echo "= = = = = = = = = = = "
echo "Which node version is it?"
node -v

echo " "
echo "= = = = = = = = = = = = = = = = = = ="
echo "prepare to load nvm in the next stage"
# do not do this with every build.  It only needs to be added once.
#echo 'export NVM_DIR="$HOME/.nvm" ' >> /home/pipeline/.bashrc
#echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm ' >> /home/pipeline/.bashrc
#echo '[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion ' >> /home/pipeline/.bashrc

echo " "
echo "= = = = = = = = = = = = = = = = = = ="
echo "contents of /home/pipeline/.bashrc:"
cat /home/pipeline/.bashrc

echo " "
echo "= = = = = = = = = = = = = = = = = = ="
currentDirectory=`pwd`
echo "Contents of directory "$currentDirectory
ls -al

echo " "

但是,在下一个管道阶段中,我希望能够使用我最近加载的节点版本。问题在于未启用最新的nodejs并将其还原为原始的默认nodejs版本。不仅如此,而且看来管道正在编辑.bashrc文件,并删除上一步中添加的行,并删除.nvm文件夹。嗯,完全奇怪。如果管道要撤消上一阶段的所有工作,则在阶段中运行bash脚本没有太大意义。

下一阶段Input设置为Input Type:构建工件。

如何在下一阶段保持NVM更新的节点版本可用?

这不是我第一次花费大量时间调试bluemix,而只是切换到另一个可以按我需要的方式运行的提供程序。


事实证明,通过将构建器类型切换为NPM并使用bluemix建议的脚本:

# To use Node.js 6.7.0, uncomment the following line:
export PATH=/opt/IBM/node-v6.7.0/bin:$PATH

选定的节点版本也将丢失到流水线的下一阶段,即与上面的我的长NVM脚本无关。

1 个答案:

答案 0 :(得分:1)

Each stage has a clean environment by design。您可以安装到该阶段中,并保留该阶段中的所有作业。您可能需要在阶段中研究运行多个作业,以便可以重用已安装的Node.js版本。那将是典型的使用场景。

Another option is to us a custom Docker image as foundation for your stage