After I upgraded gitlab yesterday, my gitlab-ci.yml file reported an error
The error message is jobs:gitkeep:only configshould be an array of strings or regexps
My config file content is
gitkeep:
stage: eslint
tags:
- chore
only:
- develop
- /^feature\/((?!snapshot$|latest$|release\/).)+?$/
- /^release\/((?!snapshot$|latest$).)+?$/
- /^dev\/((?!snapshot$|latest$).)+?$/
script:
- docker build -t mdf-modify-all .
- docker run --cpus="2.5" --rm mdf-modify-all sh -c "sh release-all.sh && git add . && git commit -m 'release all' && git push origin HEAD:$CI_COMMIT_REF_NAME"
when: manual
In some online verification tools, these configurations are legal. But in CI lint, it prompts that the regularity is illegal. How can I modify this regularity?
After I delete this regular expression, the verification is passed, but I want to keep this regular expression, how can I modify it?
Related
Trying to run a simple bash script on google cloud build. Trying to run it it says it cannot find it, even though ls shows it is there
I've set up a build trigger on google cloud to run a simple test repository on pushes to main branch
The test repository has just two files: the cloudbuild yaml and a simple testfile.sh bash script
Cloudbuild yaml tells it to run this testfile.sh file, but says it cannot find it even though a simple ls arg shows it
I've tried like every combination of ways to run a bash file:
with/without '-c' argument
with/without '.' argument
with/without file shebang
cloudbuild.yaml:
steps:
- name: 'ubuntu'
entrypoint: 'bash'
args: ['-c', 'testfile.sh']
testfile.sh:
echo "Go suck it, world!"
gcloud builds log <log-id>:
starting build "640c5ba5-5906-4296-a80c-9adc54ee84bb"
FETCHSOURCE
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: git branch -m <name>
Initialized empty Git repository in /workspace/.git/
From https://source.developers.google.com/p/test-wtf-2734586432/r/test-files
* branch 1d6fc0b27c09cb3421a242764dfe28bc115bf8f5 -> FETCH_HEAD
HEAD is now at 1d6fc0b Fix typo in entrypoint
BUILD
Pulling image: ubuntu
Using default tag: latest
latest: Pulling from library/ubuntu
Digest: sha256:adf73ca014822ad8237623d388cedf4d5346aa72c270c5acc01431cc93e18e2d
Status: Downloaded newer image for ubuntu:latest
docker.io/library/ubuntu:latest
bash: testfile.sh: command not found
ERROR
ERROR: build step 0 "ubuntu" failed: step exited with non-zero status: 127
I fixed it
Had to get rid of the '-c' from the args list
I have specified multiple deploy script providers. One which is expected to run, but skipped is:
- provider: script
skip_cleanup: true
script: curl -sL https://git.io/goreleaser | bash -s -- --rm-dist --skip-publish
verbose: true
on:
condition: "$TRAVIS_OS_NAME = linux"
branches:
only:
- /^release\/.*$/
go: 1.11.x
Last three deploys are only on master branch, so its right to skip them.
The first deploy which is on all branches matching regexp: /^release/.*$/ should run for this branch release/2.1.5. However it’s skipping this deploy too.
Can someone point why the release branch deploy is skipped in this case? I want the first deploy to run on linux and release branches only like: release/2.1.5.
Travis build: https://travis-ci.org/leopardslab/dunner/jobs/560593148
Travis Config file: https://github.com/leopardslab/dunner/blob/172a4c5792b0a8389556cc8ee4f690dc73fafb6e/.travis.yml
To run the deploy script conditionally, say only on branches matching a regular expression like release branches as ^release\/.*$, use condition field and concatenate multiple conditions using &&. The branch or branches field does not support regexp.
If branch or branches field is not specified, travis assumes its on master branch(or default branch). So be sure to include all_branches: true line in travis config.
You can access current branch name using travis env variable $TRAVIS_BRANCH.
deploy:
- provider: script
script: bash myscript.sh
verbose: true
on:
all_branches: true
condition: $TRAVIS_BRANCH =~ ^release\/.*$ && $TRAVIS_OS_NAME = linux
In my Travis CI script on Github, I have the following condition, where the default profile is run if commits are pushed to a remote branch. And test profile if it is a pull request.
script:
- 'if [ "$TRAVIS_EVENT_TYPE" == "push" ]; then
mvn clean install;
else
mvn clean install -P test;
fi'
Now the problem I am facing is that if condition also runs when there is a merge from feature to develop branch which I do not want. I want the if condition to run only when there is a push from local feature or bugfix branch to remote. To handle this I have added regular expression to match the branches like below.
script:
- 'if [ "$TRAVIS_EVENT_TYPE" == "push" && "$TRAVIS_BRANCH" =~ ^(feature|bugfix)]; then
mvn clean install;
else
mvn clean install -P test;
fi'
But it gives the following error:
The command "if [ "$TRAVIS_EVENT_TYPE" == "push" && "$TRAVIS_BRANCH" =~ ^(feature|bugfix)]; then mvn clean install; else mvn clean install -P test; fi" exited with 1.
Edit: I think matching the branch condition won't help in achieving what I am trying to do here. Since the merge will be from feature-* or bugfix-* to develop branch. So I think this additional branch check is redundant here.
So the build rules I am trying to implement are:
If it is a commit push from local branches to remote branches, then run the default profile with mvn clean install.
If it is a new pull request or pull request merge, then run the test profile with mvn clean install -P test
What will be the right checks to achieve this in Travis CI script?
I have created an automated selenium test script which works perfectly fine.
My task now is to set up Gitlab CI and try to automatically run this selenium script when I make a push to git.
Is it possible to make the selenium script automatically execute and inform the user if the script runs successfully or it fails?
Thank you
How to automatically run Automation Tests on Gitlab Ci with Selenium and specflow with a .net Project ?
If this is something ,you are looking for then .
Here is the core part which is to setup the gitlab-ci.yml file :
Here is how the sample gitlab-ci.yml should look :
image: please give your own docker which can download .net stuff
variables:
DOCKER_DRIVER: overlay2
SOURCE_CODE_DIRECTORY: 'src'
BINARIES_DIRECTORY: 'bin'
OBJECTS_DIRECTORY: 'obj'
NUGET_PACKAGES_DIRECTORY: '.nuget'
stages:
- Build
- Test
before_script:
- 'dotnet restore ${SOURCE_CODE_DIRECTORY}/TestProject.sln --packages ${NUGET_PACKAGES_DIRECTORY}'
Build:
stage: Build
script:
- 'dotnet build $SOURCE_CODE_DIRECTORY/TestProject.sln --no-restore'
except:
- tags
artifacts:
paths:
- '${SOURCE_CODE_DIRECTORY}/*/${BINARIES_DIRECTORY}'
- '${SOURCE_CODE_DIRECTORY}/*/${OBJECTS_DIRECTORY}'
- '${NUGET_PACKAGES_DIRECTORY}'
expire_in: 2 hr
Test:
stage: Test
services:
- selenium/standalone-chrome:latest
script:
- 'export MSBUILDSINGLELOADCONTEXT=1'
- 'export selenium_remote_url=http://selenium__standalone-chrome:4444/wd/hub/'
- 'export PATH=$PATH:${SOURCE_CODE_DIRECTORY}/chromedriver.exe'
- 'dotnet test $SOURCE_CODE_DIRECTORY/ExpressTestProject.sln --no-restore'
artifacts:
paths:
- '${SOURCE_CODE_DIRECTORY}/chromedriver.exe'
- '${SOURCE_CODE_DIRECTORY}/*/${BINARIES_DIRECTORY}'
- '${SOURCE_CODE_DIRECTORY}/*/${OBJECTS_DIRECTORY}'
- '${NUGET_PACKAGES_DIRECTORY}'
Thats it .When you set up your project with this .git-lab-ci.yml ,90 % of your job is done .
The tests will run automatically in Gitlab ,whenever you commit something in your source tree or Tfs.
Thanks
We sometimes struggle with updating CSS / JS files for our customers when they're cached. A common hack we found is to append an version tag to the in our sourcecode (style.min.css becomes style.min.css?v=123 for example).
We wanted to integrate that change in our Gitlab CI/CD pipelines that we already use to sync the repository with our FTP server where the websites are hosted.
I came up with the following script (note: we're using the docker:latest image)
stages:
- deploy
before_script:
- apk update
- apk add lftp
deploy:
stage: deploy
script:
- sed -i -E 's/(\.css\?|\.css\")/\.css?v='$CI_JOB_ID'\&\"/g' templates/index.php
- sed -i -E 's/(\.js\?|\.js\")/\.js?v='$CI_JOB_ID'\&\"/g' templates/index.php
- lftp -c "set ftp:ssl-allow no; open -u $FTP_USER,$FTP_PASS $FTP_HOST; mirror -Rv ./ ./gitlab-ci-test --ignore-time --parallel=10 --exclude-glob .git* --exclude .git/"
only:
- master
That's working fine, except when we use css/js files that already have an ?something=something in their reference. I want to keep that, but how...
style.min.css should become style.min.css?v=ID (this is working already with the file I have included above)
style.min.css?x=y should become style.min.css?v=ID&x=y
Can somebody help me out or come up with a better idea?
First handle the case style.min.css?x=y:
s/\.css\?/.css?v='$CI_JOB_ID'&/g
Then handle the case style.min.css:
s/\.css([^?])/.css?v='$CI_JOB_ID'$1/g