我想使用bitbucket管道,并且我有这样的bitbucket-pipelines.yml:
image: java:8
pipelines:
default:
- step:
caches:
- gradle
- android-sdk
script:
/*SOME CODE*/
# Build apk
- chmod a+x ./gradlew
- ./gradlew assembleDebug
branches:
develop:
- step:
caches:
- gradle
- android-sdk
script:
/*SOME CODE*/
# Build apk
- chmod a+x ./gradlew
- ./gradlew assembleDebug
artifacts:
- app/build/outputs/apk/debug/*.apk
definitions:
caches:
android-sdk: android-sdk
但是“脚本”中有很多相等的代码,有什么办法可以解决此问题?也许将相等的代码移到脚本上?
我已经将移动代码放入了build.sh,但是出现了错误:
+ ./build.sh
./build.sh: line 4: -: command not found
./build.sh: line 5: -: command not found
./build.sh: line 8: -: command not found
答案 0 :(得分:2)
创建#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
int
main(void)
{
int N = 300;
int L = 1000;
char Nseq[N][L];
FILE *myfile;
char *token;
const char s[2] = ",";
char *line;
int len;
char *filename = "pathtofile.txt";
int err;
struct stat st;
int n = 0;
err = stat(filename,&st);
if (err < 0) {
printf("could not stat file %s", filename);
exit(1);
}
len = st.st_size + 1;
line = malloc(len);
myfile = fopen(filename, "r");
if (myfile == NULL) {
printf("could not open file %s", filename);
exit(1);
}
while (fgets(line, len, myfile) != NULL) {
token = strtok(line, s);
while (token != NULL) {
strcpy(Nseq[n], token);
printf("%s\t%u\n", token, n);
token = strtok(NULL, s);
n++;
}
}
fclose(myfile);
return 0;
}
文件是可能的。但是,当您将脚本命令复制到文件中时,似乎没有删除'-'字符。对于给定的文件,您的mmap
应该如下所示:
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/mman.h>
int
main(void)
{
int N = 300;
int L = 1000;
char Nseq[N][L];
char *token;
char *line;
char *cur;
char *end;
char *filename = "pathtofile.txt";
int fd;
int chr;
int n = 0;
int err;
struct stat st;
size_t len;
fd = open(filename,O_RDONLY);
if (fd < 0) {
printf("could not open file %s", filename);
exit(1);
}
err = fstat(fd,&st);
if (err < 0) {
printf("could not stat file %s", filename);
exit(1);
}
len = st.st_size;
line = mmap(NULL,len,PROT_READ,MAP_PRIVATE,fd,0);
if (line == MAP_FAILED) {
printf("could not mmap file %s", filename);
exit(1);
}
cur = line;
end = &line[len];
token = Nseq[n];
for (cur = line; cur < end; ++cur) {
chr = *cur;
switch (chr) {
case ',':
case '\n':
*token = 0;
if (token > Nseq[n]) {
printf("%s\t%u\n", Nseq[n], n);
++n;
}
token = Nseq[n];
break;
default:
*token++ = chr;
break;
}
}
munmap(line,len);
close(fd);
return 0;
}
请注意,每个命令前都没有'-'。 您的bitbucket-pipelines.yml文件应如下所示:
build.sh