ERROR: Job failed: build directory needs to be an absolute path - gitlab-ci-runner

Installed Gitlab runner on windows
Registered
configured a test repo with test gitlab ci yaml configuration file
CI/CD pipelines shows error
ERROR: Job failed: build directory needs to be an absolute path
Here is the .gitlab-ci.yml :
image: busybox:latest
before_script:
- echo "Before script section"
- echo "For example you might run an update here or install a build dependency"
- echo "Or perhaps you might print out some debugging details"
after_script:
- echo "After script section"
- echo "For example you might do some cleanup here"
build1:
stage: build
script:
- echo "Do your build here"
test1:
stage: test
script:
- echo "Do a test here"
- echo "For example run a test suite"
test2:
stage: test
script:
- echo "Do another parallel test here"
- echo "For example run a lint test"
deploy1:
stage: deploy
script:
- echo "Do your deploy here"

I don't know what type of runner you have, in my case I had the same issue with docker-ssh runner. A workaround for me was to specify build_dir in config.toml
[[runners]]
name = "jira-ssh-runner"
executor = "docker-ssh"
builds_dir = "/home/gitlab-runner/build"

On windows it works with double slashes in the path
[[runners]]
name = "development-server-runner"
url = "https://*****.com"
token = "n****tq"
builds_dir = "E:\\00-gitlab-build"
executor = "shell"
shell = "powershell"
[runners.custom_build_dir]
enabled = true
[runners.cache]
[runners.cache.s3]
[runners.cache.gcs]

Related

Is git ls-remote able to use GITHUB variables? Error: Process completed with exit code 2

Actions code:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout codes
uses: actions/checkout#v2
- name: Test git for actions
shell: bash
run: |
## use GitHub variables, such as: GITHUB_REF,GITHUB_HEAD_REF..
BRANCH=${GITHUB_REF##*/}
branch=$BRANCH
git ls-remote --heads --exit-code repo_url "$branch" >/dev/null
if [ "$?" == "1" ]
then
echo "Branch doesn't exist"
else
echo "Branch exist"
fi
It will occur the following error:
BRANCH=${GITHUB_REF##*/}
branch=${BRANCH}
echo $branch
git ls-remote --heads --exit-code repo_url "$branch" >/dev/null
if [ "$?" == "1" ]
then
echo "Branch doesn't exist"
else
echo "Branch exist"
fi
shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
main
Error: Process completed with exit code 2.
When I replace ${GITHUB_REF} with main, it works fine.
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Test git for actions
shell: bash
run: |
## use GitHub variables, such as: GITHUB_REF,GITHUB_HEAD_REF..
BRANCH=${GITHUB_REF##*/}
branch=main
git ls-remote --heads --exit-code repo_url "$branch" >/dev/null
if [ "$?" == "1" ]
then
echo "Branch doesn't exist"
else
echo "Branch exist"
fi
Output:
BRANCH=${GITHUB_REF##*/}
branch=main
echo $branch
git ls-remote --heads --exit-code repo_url "$branch" >/dev/null
if [ "$?" == "1" ]
then
echo "Branch doesn't exist"
else
echo "Branch exist"
fi
main
Branch exist
Is the git ls-remote command not able to use variables?
I want to check whether a certain branch exists in the remote warehouse in GitHub Actions.
According to jobs.<job_id>.steps[*].shell, the default Bash invocation is:
bash --noprofile --norc -eo pipefail {0}
which makes it to fail fast as described under Exit codes and error action preference, for bash:
Fail-fast behavior using set -eo pipefail: This option is set when shell: bash is explicitly specified.
And, according to Bash manual, under The Set Builtin:
-e: Exit immediately if a pipeline (see Pipelines), which may consist of a single simple command (see Simple Commands), a list (see Lists of Commands), or a compound command (see Compound Commands) returns a non-zero status. The shell does not exit if the command that fails is part of the command list immediately following a while or until keyword, part of the test in an if statement, part of any command executed in a && or || list except the command following the final && or ||, any command in a pipeline but the last, or if the command’s return status is being inverted with !. If a compound command other than a subshell returns a non-zero status because a command failed while -e was being ignored, the shell does not exit. A trap on ERR, if set, is executed before the shell exits.
and,
-o pipefail: If set, the return value of a pipeline is the value of the last (rightmost) command to exit with a non-zero status, or zero if all commands in the pipeline exit successfully. This option is disabled by default.
In your case, the possible solution could be to directly handle the exit status of the command in an if:
if command; then
# succes
else
# failure
end
i.e.
if ! git ls-remote --heads --exit-code repo_url "$branch" >/dev/null
then
echo "Branch doesn't exist"
else
echo "Branch exist"
fi
or,
if git ls-remote --heads --exit-code repo_url "$branch" >/dev/null
then
echo "Branch exist"
else
echo "Branch doesn't exist"
fi

GitLab CI - passing JSON into a release-cli command with PowerShell

I'm trying to pass a JSON structure required to register a new release in GitLab, but I'm not sure how I should escape the double quotes. Here's a release job section from my gitlab-ci.yml:
release:
stage: release
tags:
- windows
rules:
- if: $CI_COMMIT_TAG
variables:
ASSET_LINK_DETAILS: "{\"name\":\"${PACKAGE_NAME}.zip\",\"url\":\"${PACKAGE_REGISTRY_URL}/${PACKAGE_NAME}.zip\"}"
script:
- 'Write-Host "Creating release..."'
- 'Start-Process -FilePath "release-cli" -ArgumentList "create --name `"Release $CI_COMMIT_TAG`" --tag-name `"$CI_COMMIT_TAG`" --asset-link ${env:ASSET_LINK_DETAILS}" -NoNewWindow -Wait'
- 'Write-Host "Finished creating release..."'
Running this job returns an error from the release-cli:
Incorrect Usage: flag provided but not defined: -asset-link
What is the correct way to pass this JSON into the command in PowerShell?
I found the answer in the GitLab release documentation, there's a complete example there. PowerShell can be a PITA...
https://docs.gitlab.com/ee/user/project/releases/release_fields.html#use-a-generic-package-for-attaching-binaries
Here's an example:
- $env:asset = "{`"name`":`"$env:PACKAGE_NAME.zip`",`"url`":`"$env:PACKAGE_REGISTRY_URL/$env:PACKAGE_NAME.zip`"}"
- $env:assetjson = $env:asset | ConvertTo-Json
- Start-Process -FilePath "C:\GitLab\Release-CLI\bin\release-cli" -ArgumentList "create --name `"$CI_COMMIT_TAG`" --description `"Release $CI_COMMIT_TAG`" --tag-name `"$CI_COMMIT_TAG`" --ref `"$CI_COMMIT_TAG`" --assets-link=$env:assetjson" -NoNewWindow -Wait

run realize start for a Go program, outputs exec: not started

when I run realize start for a Go program, I got this error result
[14:55:13][V2-USER-API.YUMMY.ID] : Watching 159 file/s 118 folder/s
[14:55:13][V2-USER-API.YUMMY.ID] : Install started
[14:55:13][V2-USER-API.YUMMY.ID] : Install
exec: not started
I have set up my file .realize.yaml, like this
settings:
legacy:
force: false
interval: 0s
schema:
- name: v2-user-api.yummy.id
path: ./cmd/server
commands:
run:
status: true
watcher:
extensions:
- go
paths:
- ../../
ignored_paths:
- .git
- .realize
- vendor
but I got error after run realize start
This command work for me
#!/usr/bin/env bash
export GO111MODULE=off
cd ~/
go get github.com/oxequa/realize
cd /go/src/github.com/oxequa/realize && \
git fetch && \
git checkout v2.0.2 && \
go get github.com/oxequa/realize
RV=$(realize --version)
echo "Realize installed #: $RV"
export GO111MODULE=on
use realize version v2.0.2

Is there a way to switch cwd by changing environment in PM2 - node.js

I am using PM2 to manage the execution of a couple of micro-apps on node.
Goal:
However I would like to be able to automatically switch settings and the cwd value based on the environment the app is executing in.
For example: on my local machine CWD should be ~/user/pm2, while on the server it needs to be E:\Programs\PM2.
Is there any way to do this using JSON config options with PM2? Is there a better way to manage the variables for different environments?
you can save a shell script, say pm2_dev.sh containing the cd command as first line.
#!/bin/bash
cd /foo/bar
pm2-dev run my-app.js
OR you can add input to your script:
# pm2_dev.sh ~/user/pm2
file should be:
#!/bin/bash
cd $1
pm2-dev run my-app.js
If you do not want to change environment by shell script, you can follow documentation way:
{ "apps" : [{
"script" : "worker.js",
"watch" : true,
"env": {
"NODE_ENV": "development",
},
"env_production" : {
"NODE_ENV": "production"
} },{
"name" : "api-app",
"script" : "api.js",
"instances" : 4,
"exec_mode" : "cluster" }] }
When running your application you should use --env option as it is written here:
--env specify environment to get
specific env variables (for JSON declaration)
Finally you can wrap configuration in a js object that conditionally returns parameters basing on current environment:
module.exports = (function(env){
if( env === 'development' )
return { folder: '~/user/pm2' };
else if( env === 'production' )
return { folder: 'E:\Programs\PM2' };
}(process.env.NODE_ENV));
Then you can require the config file and access it being sure that it returns always the correct config.

creating ipa file using command line with code signing

I am trying to create an ipa file using xcode command line including signing.
i tried searching for it, i got the commands to create ipa with out code signing.
i need the commands mainly to integrate with hudson CI.
Please suggest.
-Prahasa
This is the script which I use to integrate with Hudson and my iPhone Apps.
#!/bin/sh
CONFIGURATION="AdHoc" # or Release or Debug
# location of files included in dist (.mobileprovision, iTunesArtwork, README)
DISTDIR="_distfiles"
. build.config
MARKETING_VERSION=`agvtool what-marketing-version -terse1`
build_xcode ()
{
xcodebuild -configuration "$CONFIGURATION" -sdk $SDK
}
# CONFIGURATION for xcode build can be overridden from commandline
NEWCONFIG="$1"
if ! test "$NEWCONFIG"x = x; then
echo "=== using configuration from command line $NEWCONFIG"
CONFIGURATION="$NEWCONFIG"
fi
# XCODE check build available for specified configuration
CHECKCONFIGURATION=`xcodebuild -list | egrep "$CONFIGURATION($|\ )"`
if test "$CHECKCONFIGURATION"x = x; then
echo "ERROR: xcodebuild could not find valid build configuration $CONFIGURATION"
echo
xcodebuild -list
echo
exit
fi
VERSION="$MARKETING_VERSION ($BUILD_NUMBER)"
#######
echo "=== Building distribution package for $RELEASE - $VERSION"
echo "=== setting build number to $BUILD_NUMBER"
agvtool new-version -all "${BUILD_NUMBER}"
# XCODE make sure buildpath exists for configuration, build if missing
BUILDPATH="build/$CONFIGURATION-iphoneos"
build_xcode
if [ $? != 0 ]; then
echo "ERROR: xcodebuild not successful"
exit 1
fi
if test ! -d "$BUILDPATH"; then
echo "ERROR: xcodebuild could not build configuration $CONGIRUATION ($BUILDPATH)"
exit
fi
echo "=== Successfully built configuration $CONFIGURATION ($BUILDPATH)"
# HACK : accomodate configurations with spaces, chdir to determine app name
cd "$BUILDPATH"
# derive name of .app dir (application)
APPDIR=`ls -d *.app`
cd ../..
APPPATH="$BUILDPATH/$APPDIR"
DSYMPATH="$BUILDPATH/$APPDIR.dSYM"
if test "$APPDIR"x = x; then
APPPATH="$BUILDPATH/.app"
fi
# XCODE make sure app dir exists in buildpath, build if missing
if test ! -d "$APPPATH"; then
echo "missing $APPPATH build in $BUILDPATH, trying to build"
build_xcode
# HACK : accomodate configurations with spaces, chdir to determine app name
cd "$BUILDPATH"
# derive name of .app dir (application)
APPDIR=`ls -d *.app`
cd ../..
# check again for APPDIR/APPPATH
APPPATH="$BUILDPATH/$APPDIR"
if test "$APPDIR"x = x; then
APPPATH="$BUILDPATH/.app"
fi
if test ! -d "$APPPATH"; then
echo "ERROR: xcodebuild could not build $APPPATH configuration $CONGIRUATION ($BUILDPATH)"
exit
fi
echo "=== Successfully built $APPDIR configuration $CONFIGURATION ($BUILDPATH)"
fi
# Create directory for release package
echo " - Creating release dir"
RELEASEDIR="$RELEASEBASE/$RELEASE-$CONFIGURATION-$MARKETING_VERSION-$BUILD_NUMBER"
mkdir -p "$RELEASEDIR"
echo "RELEASEDIR = $RELEASEDIR"
echo "BUILDPATH = $BUILDPATH"
echo "APPPATH = $APPPATH"
echo "DSYMPATH = $APPPATH"
# Copy other files
cp $DISTDIR/* "$RELEASEDIR"
# .IPA file: iphone app archive file, installable by itunes
IPA=`echo $APPDIR | sed "s/\.app/\.ipa/"`
echo " - Creating $IPA payload"
mkdir -p "$RELEASEDIR/Payload/"
echo " - Copying $APPPATH to $RELEASEDIR/Payload/"
# Copy built .app to payload/ itunes-specific install dir
cp -Rp "$APPPATH" "$RELEASEDIR/Payload/"
# Build .IPA file
# this is just a zipfile with a payload/ dir with the .app, and artwork
cd "$RELEASEDIR"
# include 512x512 png of artwork, if foudn
if test -f "iTunesArtwork"; then
zip -y -r "$IPA" iTunesArtwork Payload/
rm -rf Payload iTunesArtwork
else
zip -y -r "$IPA" Payload/
rm -rf Payload
fi
cd ..
pwd
# Create .zip packaged Distribution
ZIPFILE="$RELEASE-$CONFIGURATION-$MARKETING_VERSION-$BUILD_NUMBER.zip"
DSYMZIPFILE="$RELEASE-$CONFIGURATION-$MARKETING_VERSION-$BUILD_NUMBER-dSYM.zip"
echo " - zipfile is $ZIPFILE"
echo " - Compressing release $ZIPFILE"
zip -y -r "$ZIPFILE" "$RELEASE-$CONFIGURATION-$MARKETING_VERSION-$BUILD_NUMBER"
cp -pR "../$DSYMPATH" "$RELEASE-$CONFIGURATION-$MARKETING_VERSION-$BUILD_NUMBER"
echo " - creating zip of dSYM file"
zip -y -r "$DSYMZIPFILE" "$RELEASE-$CONFIGURATION-$MARKETING_VERSION-$BUILD_NUMBER/$APPDIR.dSYM"
cd ..
echo "=== Build complete for $RELEASEBASE/$ZIPFILE"
Then, my hudson configuration looks like this:
./build.sh AdHoc
./build.sh Release
Finally, my files to archive looks like this:
_release/MobilePracticePro-*-${BUILD_NUMBER}*.zip
Hope this is helpful to you! Using Hudson is really great. Also, realize your signing key needs to be installed on the same box as hudson runs and running as same user. At least that is how it is for me.
I have been facing the same issue and resolved by using the steps give in the details of the link Xcode "Build and Archive" from command line